Jeff Peery wrote:
> Hello,
> I'm having trouble catching events from my multi threaded app. I'm
> using wxpython and running several threads under the main wxApp
> thread. One of the threads creates a COM object for an OPC server. 
> I'm using dispatchWithEvents() to get the COM object. When I do this
> the server will post an event to the OnDataChange() method in my
> application.
>  
> Everything runs wonderfully when I create the COM object within the
> main thread (wxApp). However if I create it from within a sub thread
> then the OnDataChange is not being called.
>  
> My understanding of how multithreaded applications work is basic. I'm
> using queue's and threading.locks to safely manage data. However I
> don't understand how messages and events are handled in multi threaded
> apps with different apartments. The COM object I created is a client
> to an OPC server. I suspect the server lives in a different apartment
> and that I must handle how messages and events are passed between
> different threads/apartments.
>

Every thread in a Windows application has its own message queue.  If you
create a COM object in a different thread, then its messages will all be
delivered to that thread's queue.  However, wxPython is only responding
to messages on the main thread, where you created the window.

Is there a way you can organize things to create your object in the main
thread?  If not, you need to have a message pump in the second thread
dispatching messages.  I can do that in C, but I honestly don't know how
to do that in Python.

You might ask this question on the wxPython mailing list, although it
may be a bit obscure for them.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to