SIGALRM problem

Discussion in 'Python' started by Paul Rubin, Oct 13, 2008.

  1. Paul Rubin

    Paul Rubin Guest

    I'm trying to run a command on a remote host, something like:

    result = os.popen('ssh otherhost mycommand').read()

    It is possible that the other host is down, in which case the ssh
    command hangs, so I want my script to time out if this happens:

    def timeout(*x):
    raise IOError, 'timeout'
    signal(SIGALRM, timeout)
    alarm(20)

    result = os.popen('ssh otherhost mycommand').read()

    I would expect the above to raise IOError if the ssh doesn't return
    within 20 seconds, but it seems to hang when the other host is down,
    until eventually the tcp connection times out after something like 5
    minutes (which is much longer than I want to wait).

    Anyone know if os.popen somehow pre-empts the alarm signal? If it
    does, I'd consider that a bug.

    Thanks
    --Paul
    Paul Rubin, Oct 13, 2008
    #1
    1. Advertising

  2. On Oct 13, 11:45 am, Paul Rubin <http://> wrote:
    > I'm trying to run a command on a remote host, something like:
    >
    >    result = os.popen('ssh otherhost mycommand').read()
    >
    > It is possible that the other host is down, in which case the ssh
    > command hangs, so I want my script to time out if this happens:
    >
    >    def timeout(*x):
    >       raise IOError, 'timeout'
    >    signal(SIGALRM, timeout)
    >    alarm(20)
    >
    >    result = os.popen('ssh otherhost mycommand').read()
    >
    > I would expect the above to raise IOError if the ssh doesn't return
    > within 20 seconds, but it seems to hang when the other host is down,
    > until eventually the tcp connection times out after something like 5
    > minutes (which is much longer than I want to wait).
    >
    > Anyone know if os.popen somehow pre-empts the alarm signal?  If it
    > does, I'd consider that a bug.
    >
    > Thanks
    > --Paul


    Using some Google-Fu, I found this post:

    http://mail.python.org/pipermail/python-list/2003-August/217530.html

    It's old, but it looks ok...

    Mike
    Mike Driscoll, Oct 13, 2008
    #2
    1. Advertising

  3. Paul Rubin

    Paul Rubin Guest

    Paul Rubin, Oct 13, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Is SIGALRM getting masked ???

    , Dec 17, 2007, in forum: C Programming
    Replies:
    1
    Views:
    445
    David Thompson
    Dec 30, 2007
  2. Ron Eggler

    SIGALRM in a class member?

    Ron Eggler, Aug 13, 2008, in forum: C++
    Replies:
    8
    Views:
    742
    James Kanze
    Aug 14, 2008
  3. Eric Schwartz

    timeouts with threads and SIGALRM

    Eric Schwartz, Aug 13, 2004, in forum: Ruby
    Replies:
    11
    Views:
    347
    Eric Schwartz
    Aug 20, 2004
  4. Guillaume Marcais

    SIGALRM available?

    Guillaume Marcais, Feb 14, 2005, in forum: Ruby
    Replies:
    2
    Views:
    155
    Guillaume Marcais
    Feb 15, 2005
  5. Samuel

    Catching SIGALRM in a thread

    Samuel, May 20, 2007, in forum: Perl Misc
    Replies:
    7
    Views:
    471
    zentara
    May 23, 2007
Loading...

Share This Page