[python-win32] Dispatch command hangs

Tim Roberts timr at probo.com
Thu Aug 15 22:52:05 EDT 2019


On Aug 14, 2019, at 6:12 PM, Joel Gross <jagj10 at gmail.com> wrote:

> I have a multi-threaded application that receives a large number of messages (COM objects) in sudden bursts. During this time, I've noticed that if my other thread attempts to create a new COM object via the Dispatch call, that call seems to hang until the messages have been processed. This can take more than a minute sometimes. 
> I am wondering if this is because the win32 side of things is still trying to churn through all the messages? Is there a way to preempt this behavior to ensure that the object I'm trying to create gets created immediately?
> 
This is a complicated topic.  Are you calling CoInitialize?  By default, that will create a “single-threaded apartment”, where actions get handled by a single thread.  You can try calling CoInitializeEx with COINIT_MULTITHREADED and see if that helps.

But even then, you bang up against the Python interpreter lock, which only allows the interpreter to handle one thread at a time.  I wouldn’t think you’d have to wait for the whole set of object requests to drain, but threading in Python is always tricky.
— 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20190815/12b6aa80/attachment.html>


More information about the python-win32 mailing list