Windows/COM events/strange behavior
Mark Hammond
MarkH at ActiveState.com
Mon Oct 29 17:16:27 EST 2001
Krzysztof Czarnowski wrote:
> Sat, 27 Oct 2001 05:42:26 GMT
> Mark Hammond wrote:
>
>
>>As I said, this main thread probably needs to be calling
>>PumpWaitingMessages() each time around the loop.
>>
> Well... This definitely doesn't look very elegant to me!
I don't recall saying it did to me :) One extra function call in your
main loop is hardly an imposition though.
> Anyway, if I got it well:
>
> 1. I should introduce CoInitialize()/CoUninitialize() pair in the main
> thread *and* call PumpWaitingMessages() in its loop? Right? I assume that no
> COM event will be delivered here, or will it?
The main thread does not need a CoInitialize call. pythoncom
automatically calls the apartment threaded model version.
> 2. No need to do this in other child threads (like the CORBA thread). Right?
It must be done on every thread that calls any COM function or uses any
COM objects.
> 3. Will the problem go away if:
>
> * the COM event handler is installed in a "free threaded appartment"? (can
> I do this in a threading. thread?)
>
> or
>
> * native Windows threads from ? (now module threading is used)
It depends on the app. I haven't followed your code/this thread closely
enough to remember what thread the COM event originates from.
> And generally, what would be *your* favorite solution? (my task is basically
> to receive events from a COM driven subsystem and pass them to a CORBA
> subsystem)
Again, it depends on the app. However, my favourite solution is
generally the one that works :)
"Python Programming on Win32" has a reasonably complete discussion on
threads in COM from Python's POV.
Mark.
More information about the Python-list
mailing list