COM, Tk and threads

dsavitsk dsavitsk at e-coli.net
Thu May 2 14:07:56 EDT 2002


"Jon Bills" <jon_bills at hotmail.com> wrote in message
news:8ac260fdcccb2ad97306b2c88751886f.37623 at mygate.mailgate.org...
> Hello list,
>
> I am currently working on a Python project which requires the use of COM
> to integrate with existing Windows applications, and I've run into
> trouble running a GUI at the same time. I'll attempt to explain.
> Firstly, I have a COM server written in C++, which I can't change. One
> of the interface methods takes a pointer to an IDispatch, and registers
> that interface as a callback to receive various messages. I'd like those
> messages to be displayed in a GUI window, and I'd like to write the GUI
> in Python.
>
> So, I've written a Python COM server which registers its dispinterface
> with the C++ server, and that all works fine. It also spawns a Tk GUI in
> a seperate thread, and the two threads communicate via a mutex-protected
> queue. I also have a client script which starts up the Python COM
> server, registers it with the C++ server and then tells the server to
> start the GUI thread. The problem is that I want that client script to
> wait for the GUI thread to terminate before making further calls to
> unregister the python COM server and before ending the script. Whenever
> I run the script, naturally it drops off the end and everything
> terminates. I need to be able to wait on the GUI thread, but the only
> method I've found so far results in tying up the main thread, thus
> preventing the COM server from receiving its callbacks. Is there a way
> that I can signal an event from the Python COM server to the Python
> script that the GUI thread has terminated, so that the script may wait
> on that event?

when the Python COM server is done it can write a message to a named pipe.
have the python script spawn a thead that periodically checks the pipe, and
when it finds the done message it can do what ever you want done.  this
allows the pieces to communicate w/o being tied.

depending upon how often the pipe is checked, you might either have a slight
lag in the application, or use a little more processor, but that seems
easily tuneable.

-d





More information about the Python-list mailing list