[python-win32] win32com: ServerBusy message

mauro tizianel mauro.tiz at gmail.com
Wed Jan 30 17:02:27 CET 2008


Thans a lot for your answer. In an indirect way it brought me towards the
solution.

"command-line window" was a bad way to indicate PythonWin, IPython shell or
just the Python interactive prompt running python.exe from command line.
After trying without success also "python.exe < test.py" I figured out that
the main difference with the interactive prompt was in the time which
elapses between the execution of each line.

I also found somewhere:

> 1) You call a method of the COM server that takes a lot of time
> 2) Before it is done, you call a method of the same COM server.
> 3) The COM server detects it is busy with the first request and returns
> BUSY, causing COM to put up the error message.

> The fix is not to call the COM server while it is busy performing requests

> on your behalf.

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...?

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.

After a while I realized that:
1. Even if I hide the GUI (.Visible = False), the application keep the focus
after I call Dispatch. That'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.
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.

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)?

Mauro

2008/1/30, Mark Hammond <mhammond at skippinet.com.au>:
>
>  If by "command-line window" you mean the interactive prompt in pythonwin,
> IDLE or any other GUI environment, the problem will likely be the lack of a
> "message pump" (google for that, particularly on this list).  Although if
> "command-line window" means running python.exe from a command-prompt and
> entering the commands there, I've no idea why it would work interactively
> but fail when run by python.exe as a script.
>
>
>
> Hope this helps,
>
>
>
> Mark
>
>
>
> *From:* python-win32-bounces at python.org [mailto:
> python-win32-bounces at python.org] *On Behalf Of *mauro tizianel
> *Sent:* Wednesday, 30 January 2008 4:09 AM
> *To:* python-win32 at python.org
> *Subject:* [python-win32] win32com: ServerBusy message
>
>
>
> Hi list,
>
> I am calling  a method on a COM server within a python script. The method
> takes a long time to return ( > 15s) and I am getting  a "Server Busy" popup
> message "This action cannot be completed because the program is busy." To
> continue the user has to click ( "Switch to..." or "Retry").
>
> Typing in the command-line window:
> --------
> from win32com.client import Dispatch
> myComObj = Dispatch("myApp.Application")
> anotherComObj = myComObj.method()
> res = anotherComObj.thisIsAVeryLongOperation()
> --------
> 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?
>
> I tried to get rid of the popup with the solution proposed in
> http://mail.python.org/pipermail/python-win32/2006-August/004923.html
> --------
> import win32ui
> import win32uiole
> from win32com.client import Dispatch
>
> win32uiole.AfxOleInit()
> win32uiole.SetMessagePendingDelay(aBigDelay);
> win32uiole.EnableNotRespondingDialog(False);
> win32uiole.EnableBusyDialog(False);
>
> myComObj = Dispatch("myApp.Application")
> anotherComObj = myComObj.method()
> res = anotherComObj.thisIsAVeryLongOperation()
> --------
> without any effect.
>
> pythoncom.CoInitialize() should  also work, as suggested in
> http://support.microsoft.com/?scid=kb%3Ben-us%3B248019&x=14&y=15,  but
> again no positive effect.
>
> I was now looking for something like (
> http://support.microsoft.com/kb/240809/en-us):
> OLERequestPendingTimeout
> to turn off the messages, but it seems not to be available in pywin32.
>
> By the way, I am running:
>
> Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)]
> pywin32-210.win32-py2.4
> WinXP SP2
>
> Thanks in advance. Any suggestion is welcome!
>
> Mauro
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20080130/897d2b7e/attachment.htm 


More information about the python-win32 mailing list