Thans a lot for your answer. In an indirect way it brought me towards the solution.<br><br><span style="font-size: 11pt; color: rgb(31, 73, 125);">&quot;command-line window&quot;</span> was a bad way to indicate PythonWin, IPython shell or just the Python interactive prompt running python.exe from command line.<br>


After trying without success also &quot;python.exe &lt; test.py&quot; I figured out that the main difference with the interactive prompt was in the time which elapses between the execution of each line.<br><br>I also found somewhere:<br>


<br>&gt; 1) You call a method of the COM server that takes a lot of time<br>&gt; 2) Before it is done, you call a method of the same COM server.<br>&gt; 3) The COM server detects it is busy with the first request and returns <br>


&gt; BUSY, causing COM to put up the error message.<br><br>&gt; The fix is not to call the COM server while it is busy performing requests <br>&gt; on your behalf.<br><br>Thus adding a time.sleep( ) call before calling the long operation method I got the script running. The question then is: Why the function returns if I then have to wait...?<br>


<br>BUT this was only one of the problems: if the user does some other operation in the meanwhile (like switching to another application while waiting for the output) the message MAY appear again.<br><br>After a while I realized that:<br>

1. Even if I hide the GUI (.Visible = False), the application keep the focus after I call Dispatch. That&#39;s why I never get the messages in the interactive-prompt: I am activating the python prompt window by typing a command: this way the application looses the focus.<br>

2. The server busy message comes from the application, not from Python. Since the application get the focus, when the user does some other operation the first thing he does is interacting with the application, which is currently busy with the Python request... hence the message.<br>

<br>Starting the application (using Dispatch) and minimizing it manually before running the script seems to solve also this problem. Is there a way to do so automatically (.Visible = True, get in some way the handle of the window and call some win32api function to minimize the window)?<br>

<br>Mauro<br>
<br><div><span class="gmail_quote">2008/1/30, Mark Hammond &lt;<a href="mailto:mhammond@skippinet.com.au" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">mhammond@skippinet.com.au</a>&gt;:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">











<div link="blue" vlink="purple" lang="EN-US">

<div>

<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">If by &quot;command-line window&quot; you mean the interactive
prompt in pythonwin, IDLE or any other GUI environment, the problem will likely
be the lack of a &quot;message pump&quot; (google for that, particularly on
this list).&nbsp; Although if &quot;command-line window&quot; means running
python.exe from a command-prompt and entering the commands there, I&#39;ve no idea
why it would work interactively but fail when run by python.exe as a script.</span></p>

<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">&nbsp;</span></p>

<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">Hope this helps,</span></p>

<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">&nbsp;</span></p>

<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">Mark</span></p>

<p><span style="font-size: 11pt; color: rgb(31, 73, 125);">&nbsp;</span></p>

<div style="border-style: none none none solid; border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color blue; border-width: medium medium medium 1.5pt; padding: 0cm 0cm 0cm 4pt;">

<div>

<div style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0cm 0cm;">

<p><b><span style="font-size: 10pt;">From:</span></b><span style="font-size: 10pt;">
<a href="mailto:python-win32-bounces@python.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">python-win32-bounces@python.org</a> [mailto:<a href="mailto:python-win32-bounces@python.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">python-win32-bounces@python.org</a>] <b>On
Behalf Of </b>mauro tizianel<br>
<b>Sent:</b> Wednesday, 30 January 2008 4:09 AM<br>
<b>To:</b> <a href="mailto:python-win32@python.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">python-win32@python.org</a><br>
<b>Subject:</b> [python-win32] win32com: ServerBusy message</span></p>

</div>

</div><div><span>

<p>&nbsp;</p>

<p style="margin-bottom: 12pt;">Hi list,<br>
<br>
I am calling&nbsp; a method on a COM server within a python script. The method
takes a long time to return ( &gt; 15s) and I am getting&nbsp; a &quot;Server
Busy&quot; popup message &quot;This action cannot be completed because the
program is busy.&quot; To continue the user has to click ( &quot;Switch
to...&quot; or &quot;Retry&quot;).<br>
<br>
Typing in the command-line window:<br>
--------<br>
from win32com.client import Dispatch<br>
myComObj = Dispatch(&quot;myApp.Application&quot;)<br>
anotherComObj = myComObj.method()<br>
res = anotherComObj.thisIsAVeryLongOperation()<br>
--------<br>
everything works fine (no popup message, thisIsAVeryLongOperation returning
without user interaction) but if I put it into a file and run it as a script
the message appears: why?<br>
<br>
I tried to get rid of the popup with the solution proposed in <a href="http://mail.python.org/pipermail/python-win32/2006-August/004923.html" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://mail.python.org/pipermail/python-win32/2006-August/004923.html</a><br>



--------<br>
import win32ui<br>
import win32uiole<br>
from win32com.client import Dispatch<br>
<br>
win32uiole.AfxOleInit()<br>
win32uiole.SetMessagePendingDelay(aBigDelay);<br>
win32uiole.EnableNotRespondingDialog(False);<br>
win32uiole.EnableBusyDialog(False);<br>
<br>
myComObj = Dispatch(&quot;myApp.Application&quot;)<br>
anotherComObj = myComObj.method()<br>
res = anotherComObj.thisIsAVeryLongOperation()<br>
--------<br>
without any effect.<br>
<br>
pythoncom.CoInitialize() should&nbsp; also work, as suggested in <a href="http://support.microsoft.com/?scid=kb%3Ben-us%3B248019&amp;x=14&amp;y=15" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://support.microsoft.com/?scid=kb%3Ben-us%3B248019&amp;x=14&amp;y=15</a>,&nbsp;
but again no positive effect.<br>
<br>
I was now looking for something like (<a href="http://support.microsoft.com/kb/240809/en-us" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://support.microsoft.com/kb/240809/en-us</a>):
<br>
OLERequestPendingTimeout<br>
to turn off the messages, but it seems not to be available in pywin32.<br>
<br>
By the way, I am running:<br>
<br>
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]<br>
pywin32-210.win32-py2.4<br>
WinXP SP2<br>
<br>
Thanks in advance. Any suggestion is welcome!<br>
<br>
Mauro</p>

</span></div></div>

</div>

</div>


</blockquote></div><br>