Clean-up of threaded server

Michael Ströder michael at stroeder.com
Mon Apr 9 11:12:09 EDT 2001


HI!

I have a multi-threaded HTTP server (mainly based on
SocketServer.ThreadingMixIn). The main thread spawns a separate
helper thread during importing a module which is used to clean up
session data hanging around. It looks like this:

class CleanUpThread(threading.Thread):
  """
  Thread class for clean-up thread
  """
  def __init__(self,cgiSession,interval=60):
    self._cgiSession = cgiSession
    self.interval = interval
    threading.Thread.__init__(self)

  def run(self):
    """Thread function for cleaning up session database"""
    while 1:
      self._cgiSession.CleanUp()
      time.sleep(self.interval)
    return

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.

Does anybody have a clue how to solve this? Any thread tutorials for
Python?

Ciao, Michael.



More information about the Python-list mailing list