On 11Nov2015 16:16, Ulli Horlacher <frams...@rus.uni-stuttgart.de> wrote:
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?

I suggest you look at the socket.settimeout function. Avoid SIGALRM altogether. Then (untested):

 import socket
 ...
 socket.settimeout(timeout_in_seconds)
 ...
 while True:
   ...
   chunk = fileo.read(bs)
   try:
     sock.sendall(chunk)
   except socket.timeout as e:
     ... complain about timeout, reciting "e" in the message ...

Cheers,
Cameron Simpson <c...@zip.com.au>

I think you're confusing "recognizing" and "understanding" with "caring".
The net is cruel, sometimes, but always fair.
       - Rick Gordon <ri...@crl.com>
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to