cross platform alternative for signal.SIGALRM?

Ulli Horlacher framstag at rus.uni-stuttgart.de
Wed Nov 11 12:06:46 EST 2015


Marko Rauhamaa <marko at pacujo.net> wrote:
> Ulli Horlacher <framstag at rus.uni-stuttgart.de>:
> 
> > What is the best practise for a cross platform timeout handler?
> 
> Here's the simplest answer:
> 
>    https://docs.python.org/3/library/threading.html#threading.Timer
> 
> (Also available in Python 2.)

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)


gives:


start
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 759, in run
    self.function(*self.args, **self.kwargs)
  File "x.py", line 7, in hello
    def hello(): raise ValueError("hello!!!")
ValueError: hello!!!

end



-- 
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum IZUS/TIK         E-Mail: horlacher at tik.uni-stuttgart.de
Universitaet Stuttgart         Tel:    ++49-711-68565868
Allmandring 30a                Fax:    ++49-711-682357
70550 Stuttgart (Germany)      WWW:    http://www.tik.uni-stuttgart.de/



More information about the Python-list mailing list