Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98672
| From | Cameron Simpson <cs@zip.com.au> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: cross platform alternative for signal.SIGALRM? |
| Date | 2015-11-12 16:20 +1100 |
| Message-ID | <mailman.255.1447307382.16136.python-list@python.org> (permalink) |
| References | <n1vpl3$hrl$1@news2.informatik.uni-stuttgart.de> |
On 11Nov2015 16:16, Ulli Horlacher <framstag@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 <cs@zip.com.au>
I think you're confusing "recognizing" and "understanding" with "caring".
The net is cruel, sometimes, but always fair.
- Rick Gordon <rickg@crl.com>
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
cross platform alternative for signal.SIGALRM? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-11 16:16 +0000
Re: cross platform alternative for signal.SIGALRM? Marko Rauhamaa <marko@pacujo.net> - 2015-11-11 18:30 +0200
Re: cross platform alternative for signal.SIGALRM? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-11 17:06 +0000
Re: cross platform alternative for signal.SIGALRM? Marko Rauhamaa <marko@pacujo.net> - 2015-11-11 20:03 +0200
Re: cross platform alternative for signal.SIGALRM? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-11 22:42 +0000
Re: cross platform alternative for signal.SIGALRM? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-11-11 19:42 -0500
Re: cross platform alternative for signal.SIGALRM? Terry Reedy <tjreedy@udel.edu> - 2015-11-11 20:37 -0500
Re: cross platform alternative for signal.SIGALRM? Marko Rauhamaa <marko@pacujo.net> - 2015-11-12 08:14 +0200
Re: cross platform alternative for signal.SIGALRM? Christian Gollwitzer <auriocus@gmx.de> - 2015-11-12 07:43 +0100
Re: cross platform alternative for signal.SIGALRM? Chris Angelico <rosuav@gmail.com> - 2015-11-12 18:37 +1100
Re: cross platform alternative for signal.SIGALRM? Terry Reedy <tjreedy@udel.edu> - 2015-11-12 05:15 -0500
Re: cross platform alternative for signal.SIGALRM? Chris Angelico <rosuav@gmail.com> - 2015-11-12 22:38 +1100
Re: cross platform alternative for signal.SIGALRM? Terry Reedy <tjreedy@udel.edu> - 2015-11-12 09:01 -0500
Re: cross platform alternative for signal.SIGALRM? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-12 07:22 +0000
Re: cross platform alternative for signal.SIGALRM? Marko Rauhamaa <marko@pacujo.net> - 2015-11-12 10:15 +0200
Re: cross platform alternative for signal.SIGALRM? Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2015-11-12 06:58 +0000
Re: cross platform alternative for signal.SIGALRM? Cameron Simpson <cs@zip.com.au> - 2015-11-12 16:20 +1100
csiph-web