Alex schrieb:
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
run:
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)
t.start()
# Loop
while True:
...many lines....
This works for me:
import threading
import time
def work():
while True:
pass
t = threading.Thread(target=work)
t.setDaemon(True)
t.start()
time.sleep(10)
raise SystemExit
The trick is to raise the SystemExit in the main-thread.
Diez
--
http://mail.python.org/mailman/listinfo/python-list