[python-win32] COM with timeouts?

Stephen Hansen apt.shansen at gmail.com
Mon Feb 9 23:41:58 CET 2009


>> Any tips on an approach to take to interrupt a COM call or set a timeout on it?
>>
>
> There's no reliable way to do that.  You could, of course, spin off a
> separate thread to simulate SIGALRM using time.sleep, but once you had
> done so, there's no good way to stop the thread that is blocked waiting
> for Word to respond.  And if word has displayed a modal error box, it's
> not trivial to kill it in a clean way.

Doh. I was hoping I had just missed a convenient timeout function.
Killing word itself is no problem: in my scenario its okay to do so
violently, as the reinitialization procedure goes through a lot of
effort to clean up the newly started word instance.

Soo, I'm going to try a subprocess approach. Launch a subprocess which
will actually drive Word, and send messages to it in a non-blocking
fashion; then I can just kill that process if the parent's timeout
expires on any given action. Way more work then I was hoping to do,
but hey :)

Thanks.

--S


More information about the python-win32 mailing list