Prev: Capturing output of os.system to a string
Next: (pywin related) pywintypes.com_error: -2147417846 "Applicationbusy"
From: Alexander Eisenhuth on 25 Nov 2009 07:49
I'm having a problem with a python COM Excel client that rarely gets the
exception pywintypes.com_error with the error code -2147417846. (means Excel is
busy) Here the python code of the exception handling:
# write a excel cell
except pywintypes.com_error, ex:
if ex == -2147417846:
# retry write?
My first approach was to retry the writing to the excel cell. But that ends in a
hanging Excel application (probably a deadlock).
After a little research I found this post:
"[...] If you don't register a MessageFilter yourself (by calling
CoRegisterMessageFilter), you will get default behavior which will be to fail
the call if it gets rejected. .Net converts the failure HRESULT to an
exception. To deal with the possibility of the server being busy when you try
to call, you need to implement IMessageFilter::RetryRejectedCall in your client
code and also register the message filter. In most cases, you will just need to
wait for a few seconds and then retry the call--generally that will be
sufficient time to enable Word to finish whatever it is doing so it can handle
your call. However, if the instance of Word that you are controlling could
possibly visible, you might want to add additional logic to display the
OLEUIBUSY dialog after some amount of time has passed to notify the user that
you are waiting on Word to do something and give them the opportunity to help
the process. For example, as Misha mentions, Word will reject all incoming
calls if a modal dialog box is up. Therefore, in that situation, you would be
blocked indefinitely until the dialog is dismissed. [...]"
As this part of the COM API (IMessageFilter, CoRegisterMessageFilter) isn't
included in pywin32 I don't see a possibility to do that, or?
Did anybody else have to deal with that problem?
Any hints are very welcome.
From: Michel Claveau - MVP on 25 Nov 2009 07:55
Your computer is too slow, for launch Excel.
Configure the machine for more speed...