From: Alexander Eisenhuth on
Hello list,

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:

[...]
try:
# write a excel cell
[...]
except pywintypes.com_error, ex:
if ex[0] == -2147417846:
time.sleep(1.0)
# 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:

http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/70ef972b-51b6-4ece-a4af-d6b4e111eea5

"[...] 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.

Regards
Alexander
From: Michel Claveau - MVP on
Hi!

Your computer is too slow, for launch Excel.
Configure the machine for more speed...

@+
--
MCI