Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98662
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: cross platform alternative for signal.SIGALRM? |
| Date | 2015-11-11 20:37 -0500 |
| Message-ID | <mailman.251.1447292269.16136.python-list@python.org> (permalink) |
| References | <n1vpl3$hrl$1@news2.informatik.uni-stuttgart.de> |
On 11/11/2015 11:16 AM, Ulli Horlacher wrote:
> I am rewriting a Perl program into Python (2.7).
I recommend using 3.4+ if you possibly can.
> 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:
> 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?
The cross-platform 3.4 asyncio module has some functions with timeouts.
(3.5 has new 'async' syntac which supposedly makes it easier to use. I
have not looked at this yet.)
For instance: coroutine asyncio.wait(futures, *, loop=None,
timeout=None, return_when=ALL_COMPLETED)
Wait for the Futures and coroutine objects given by the sequence
futures to complete. Coroutines will be wrapped in Tasks. Returns two
sets of Future: (done, pending).
...
Usage:
done, pending = yield from asyncio.wait(fs)
I believe the backport on pypi.python.org, called tulip, works on 2.7.
In the example above, the read/send would be a task. Wait on the task,
and when it returns, cancel the task if in pending.
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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