[python-win32] Win32com events, multithreading, and re-entrancy
Moore, Paul
Paul.Moore@atosorigin.com
Mon, 30 Sep 2002 15:20:04 +0100
From: Mark Hammond [mailto:mhammond@skippinet.com.au]
> Or, it is possible that the access to Properties() is raising
> an exception. Try a "finally" clause that prints after the call,
> or even a full-blown try/except clause using the traceback module.
Ow! It never occurred to me that an exception could disappear =
completely, even if it occurred in a thread. That is indeed exactly what =
was happening.
> The next version of win32all should print these exceptions to stderr
> by default.
That will be good. I don't know enough about Python's internals, clearly =
- is this something specific to win32all, or could "normal" Python =
thread code do the same? I notice that raising SystemExit from a =
callback procedure doesn't exit the program either, something that the =
Python thread documentation states will work, so I guess there's =
something specific to win32all going on here.
> It is not clear what you expect by "atomic" here.
What I meant is that I don't understand what's going on clearly enough =
:-) On rethinking, it becomes obvious that all I really meant was "I =
don't understand why my code doesn't get past the access to =
Properties()", to which the appropriate answer is "because it raised an =
exception" :-)
> *dig dig* - I managed to get a test case working. There are a
> couple of problems, both of which would have shown up with
> printing the traceback as I mentioned above.
And they did, when I checked for myself.
> def OnConnectComplete(self, error, status, connection):
>
> In this case, connection is a PyIUnknown object - this is strange,
> and VB obviously handles this better.
That's not particularly surprising to me :-( ADO appears to be the most =
anything-other-than-VB-hostile interface I have ever seen. I've also had =
trouble setting properties on a connection, but as there are about 10 =
different ways of doing the same thing in ADO, I used one of the other =
ones and ignored the problem...
> I am fixing win32com so it does too.
Thank you.
> For now, you can use the code:
>
> connection =3D =
Dispatch(connection.QueryInterface(pythoncom.IID_IDispatch))
>
> And everything will work.
And indeed it does.
Thank you for looking into this for me.
Paul.