Making a timebomb
Cantankerous Old Git
CantankerousOldGit at gmail.com
Sun Aug 7 14:02:01 CEST 2005
Peter Hansen wrote:
> Cantankerous Old Git wrote:
>> callmebill at gmail.com wrote:
>>> I have a server that right now runs infinitely. I'd like to make it
>>> die after some amount of time.
>> The proper way to do it is to have the timer set a flag that the other
>> threads check regularly. The threads can then clean up and exit asap.
>> The dirty way, which can leave corrupt half-written files and other
>> nasties, is something like sys.exit().
> sys.exit() won't help you if your server is running in the main thread,
> nor if your server thread is not marked as a daemon, but that does raise
> another possibility. Instead of doing serve() in the main thread, spawn
> off a child thread to do the serving, and call setDaemon(True) on it.
> Then the _main_ thread can do sys.exit() and the server thread will be
> terminated (somewhat messily perhaps) -- even if it is blocked in an
> accept() call or some other external blocking call.
I assume you know that I actually meant System.exit(). Why do you
think that won't help?
More information about the Python-list