cross platform alternative for signal.SIGALRM?

Ulli Horlacher framstag at rus.uni-stuttgart.de
Wed Nov 11 11:16:35 EST 2015


I am rewriting a Perl program into Python (2.7).
It must run on Linux and Windows.
With Linux I have no problems, but Windows... :-(

The current show stopper is signal.SIGALRM which is not available on
Windows:

  File "fexit.py", line 674, in formdata_post
    signal.signal(signal.SIGALRM,timeout_handler)
  AttributeError: 'module' object has no attribute 'SIGALRM'


  https://docs.python.org/2/library/signal.html

  signal.alarm(time) (...) Availability: Unix.

Perl for Windows has had SIGALRM support (or some kind of emulation).

Ok, I have to redesign this part of my code:

  def timeout_handler(sig,frame): 
    raise ValueError("timeout!")
    
  signal.signal(signal.SIGALRM,timeout_handler)

  while True:
    chunk = fileo.read(bs)
    sock.sendall(chunk)
    (...)


What is the best practise for a cross platform timeout handler?




-- 
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