How to Force exiting from program/script
Diez B. Roggisch
deets at nospam.web.de
Wed Jul 15 17:39:01 EDT 2009
> hi at all,
> I have made a script with a while loop and I want that after 30
> seconds the program stop and exit . But the code like this doesn't
> In the Console I can see work so that function is correctly called...
> #Function to exit
> def exit():
> print "work"
> raise SystemExit()
> t = threading.Timer(30.0, exit)
> # Loop
> while True:
> ...many lines....
This works for me:
t = threading.Thread(target=work)
The trick is to raise the SystemExit in the main-thread.
More information about the Python-list