Clean-up of threaded server

David Bolen db3l at fitlinxx.com
Mon Apr 9 13:44:38 EDT 2001


Michael =?iso-8859-1?Q?Str=F6der?= <michael at stroeder.com> writes:

> I have two problems:
> 
> 1. The server process does not detach from the console anymore (fork
> is used for that). This seems to work without the separate helper
> thread.
> 
> 2. For testing purposes the server process can be started
> non-detached. In this case KeyboardInterrupt is catched by the main
> thread to shut down the process. This does not work with the helper
> thread but works without it.

I'm not sure about (1) (perhaps depending on environment, the other
thread has its own reference to file handles that you normally close
before detaching, and you could try closing them before starting up
the thread?)

But for (2) if you have multiple threads around, then Python is going
to wait for those other threads to terminate when you try to exit
(it's basically the same as you doing a join() on each thread).  So to
properly exit, you would want to write your helper threads to look for
some sort of sentinel or receive a message to tell them to exit when
you want the script to exit.

Alternatively, threads can be marked as a "daemon" via the threading
module setDaemon method, and those threads are permitted to still be
executing when the script exits.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list