cross platform alternative for signal.SIGALRM?
Marko Rauhamaa
marko at pacujo.net
Wed Nov 11 13:03:12 EST 2015
Ulli Horlacher <framstag at rus.uni-stuttgart.de>:
> Hmmm... not so simple for me. My test code:
>
> from time import *
> import threading
> import sys
>
> def hello():
> raise ValueError("hello!!!")
>
> t = threading.Timer(3.0,hello)
> t.start()
> try:
> print "start"
> sleep(5)
> print "end"
> except ValueError as e:
> print e.args[0]
> sys.exit(1)
Correct. The timer callback function (hello) would be called in a
separate thread. An exception raised in one thread cannot be caught in
the main thread. In general, there is no way for a thread to interrupt a
sibling thread that is in a blocking function call.
Marko
More information about the Python-list
mailing list