I really do not know if the timeout
argument to asyncore.loop()
really is meant to timeout the function call asyncore.loop()
after the specified time, but here is a receipt to make that function timeout after a specified time (replacing the line with asyncore.loop()
in the example code):
import signal
class TimeoutError(Exception): pass
# define the timeout handler
def handler(signum, frame):
raise TimeoutError()
# set the timeout handler and the signal duration
signal.signal(signal.SIGALRM, handler)
signal.alarm(1)
try:
asyncore.loop()
except TimeoutError as exc:
print "timeout"
finally:
signal.alarm(0)