COM server threads/unloading

Kris J. Zaragoza kzaragoza at attbi.com
Thu Jun 27 21:09:22 CEST 2002


In article <10d944cb.0206261529.741da082 at posting.google.com>, Uncle Enzo wrote:
> Then I added the googlelogger import statement and the two lines
> initializing and calling the log method. The logger that has two
> threads. Using the same client code results in the testserver.exe
> loading after the dispatch call, but it does not unload after the
> server reference is set to None, nor does it unload after the client
> terminates.
>
> What is the proper way to get a multithreaded python COM server to
> unload when there are no external references to it?

Mark makes some good suggestions in his reply to you.  However, your
problem appears to have nothing to do with COM and everything to do
with threading.  In your googlelogger module, you create a thread that
runs in an infinite loop.  You built a mechanism to shut down the
thread by sending it a magic QUIT command.  However, your COM
component never sends it that command.  Your server doesn't shut down
because you have threads still running waiting on a queue that will
never contain more messages.

As I see it, you have two options.  First, you can build a mechanism
to explicitly send the logger the message to shut down.  Second, you
can set the logging threads to be daemon threads with setDaemon().
This will flag the thread such that it will not keep the process from
exiting when all other threads have terminated.  It's a quick and easy
way to terminate the thread without having to explicitly tell it to
shut down.

Then again, as Tim Peters writes, "Explicit is better than implicit."

-Kris

-- 
Kris J. Zaragoza       | On the face of it, Microsoft complaining about
kzaragoza at attbi.com    | the source license used by Linux is like the
                       | event horizon calling the kettle black.
                       | -- Adam Barr, article on kuro5hin.org



More information about the Python-list mailing list