Multithreaded COM server problem...
mhammond at skippinet.com.au
Mon Jan 12 06:48:27 CET 2004
John Lull wrote:
> Mark Hammond <mhammond at skippinet.com.au> wrote (with possible deletions):
>>John Lull wrote:
>>>I'm writing a multithreaded COM server to manage a pool of hardware resources.
>>>All objects are designed to be thread-safe, and I've set sys.coinit_flags to
>>>COINIT_MULTITHREADED before importing pythoncom.
>>Note that this flag is effeectively ignored for the server. Objects are
>>created in the same "apartment" as their creator. This, the code
>>implementing your object need not specify this, but the code *creating*
>>the object must. This is what determines the appartment.
>>COM threading rules are complex, but "Python Programming on Win32" (1/2
>>by me :) covers these rules in words I would have trouble finding again :)
> It covers threading rules for in-process servers pretty thoroughly.
> Unfortunately, this one has to be a local server since it's providing shared
> access to a pool of hardware devices from multiple distributed clients. I've
> carefully reviewed chapters 5 & 12, and appendix D, and wasn't able to find
> anything addressing threading models in the local server in detail. If I've
> missed something, I'd be grateful for any additional hints.
The problem is that your client code is not running a message loop. If
you change the loop of your client test code to something like:
for i in range(delay)*10:
It works as you expect. A better choice would probably be
win32event.MsgWaitForMultipleObjects, but that depends on what your app
More information about the Python-list