[python-win32] Win32com events, multithreading, and re-entrancy

Mark Hammond mhammond@skippinet.com.au
Thu, 26 Sep 2002 12:29:13 +1000


> This is an ADO program, trying to catch the ADO connection
> events. The program works fine, *as long as* the print statement
> in OnConnectComplete is commented out. Any attempt to access the
> connection object from within the event handler causes Python to
> jump back into the main busy wait loop, pumping messages and
> printing dots.

It's not clear what the problem is.  Accessing the connection object may
well cause the main loop to trigger, but it should still work.  What exactly
is the problem?

> I assume that this is somehow related to the internal
> multithreading and serialisation that goes on in COM, but I don't
> know enough about that to understand it. Trying to make the code
> free-threaded (assigning to sys.coinit_flags - BTW, there's a bug
> in the documentation for pythoncom.CoInitializeEx, which gives 2
> variations on this name) didn't seem to help.

OVe fixed the doc.  ADO is probably single or apartment threaded, thus it
will not depend on your sys.coinit_flags.

> How do I do this? Is there any sample code which shows how to do
> this? Mark Hammond's book doesn't cover ADO events, and I've read
> the threading appendix and am still no wiser...

I'm not exactly clear what you are trying to do!

Mark.