Making a timebomb

callmebill at gmail.com callmebill at gmail.com
Fri Aug 5 11:10:06 EDT 2005


I have a server that right now runs infinitely.  I'd like to make it
die after some amount of time.  I was thinking of having a timebomb
thread that starts when the server starts.  The timebomb sits, and
sleeps for the specified timeout period (e.g., 5 hours), then does
something to make the main thread terminate.  But I'm too inexperienced
to figure out what that thing is.

Any suggestions?



class TimeBomb( threading.Thread ):
   def run(self):
       timeout = 5 * 60 * 60 #-- 3 hours
       time.sleep( timeout )
       MakeTheRestOfTheStuffDie()

class MyServer:
   def __init__(self):
       TimeBomb().run()
       serve()




More information about the Python-list mailing list