Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98672

Re: cross platform alternative for signal.SIGALRM?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Cameron Simpson <cs@zip.com.au>
Newsgroups comp.lang.python
Subject Re: cross platform alternative for signal.SIGALRM?
Date Thu, 12 Nov 2015 16:20:46 +1100
Lines 53
Message-ID <mailman.255.1447307382.16136.python-list@python.org> (permalink)
References <n1vpl3$hrl$1@news2.informatik.uni-stuttgart.de>
Reply-To python-list@python.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii; format=flowed
X-Trace news.uni-berlin.de s9edIgZgP6P2RoVvWI5bcAAx8A92ZHV3RoLteZzG/ugQ==
Return-Path <cameron@cskk.homeip.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:skip:s 10': 0.05; ':-(': 0.07; 'chunk': 0.07; 'socket': 0.07; 'cc:addr:python-list': 0.09; 'timeout': 0.09; 'python': 0.10; 'def': 0.13; 'suggest': 0.15; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'rewriting': 0.16; 'simpson': 0.16; 'subject:alternative': 0.16; 'timeout,': 0.16; 'true:': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'try:': 0.18; 'windows': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'cheers,': 0.22; 'cc:no real name:2**0': 0.22; '(or': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'linux': 0.26; 'complain': 0.29; 'perl': 0.29; 'code:': 0.29; 'raise': 0.29; 'skip:s 30': 0.31; 'run': 0.33; 'url:python': 0.33; 'windows.': 0.33; 'file': 0.34; 'except': 0.34; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'skip:v 20': 0.38; 'skip:s 40': 0.38; 'some': 0.40; 'avoid': 0.61; 'show': 0.62; 'cameron': 0.66; 'header:Reply-To:1': 0.67; 'reply- to:no real name:2**0': 0.71; 'received:61': 0.72; '>with': 0.84; 'confusing': 0.84; 'reply-to:addr:python.org': 0.84; 'rick': 0.93
X-Authentication-Info Submitted using ID cskk@bigpond.com
X-Authority-Analysis v=2.0 cv=JY8+XD2V c=1 sm=1 a=w8UANqRlQPdik3ney68ylg==:17 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=8AHkEIZyAAAA:8 a=qtqOOiqGOCEA:10 a=K8_jpOyAAAAA:8 a=7HZYEeCsNOFu573pOl8A:9 a=CjuIK1q_8ugA:10 a=NOGS43Lr1mwA:10 a=w8UANqRlQPdik3ney68ylg==:117
Content-Disposition inline
In-Reply-To <n1vpl3$hrl$1@news2.informatik.uni-stuttgart.de>
User-Agent Mutt/1.5.23 (2014-03-12)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:98672

Show key headers only | View raw


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 | NextPrevious in thread | Find similar | Unroll thread


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