SIGALRM problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Rubin

    SIGALRM problem

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

    result = os.popen('ssh otherhost mycommand').rea d()

    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').rea d()

    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
  • Mike Driscoll

    #2
    Re: SIGALRM problem

    On Oct 13, 11:45 am, Paul Rubin <http://phr...@NOSPAM.i nvalidwrote:
    I'm trying to run a command on a remote host, something like:
    >
       result = os.popen('ssh otherhost mycommand').rea d()
    >
    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').rea d()
    >
    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:



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

    Mike

    Comment

    • Paul Rubin

      #3
      Re: SIGALRM problem

      Mike Driscoll <kyosohma@gmail .comwrites:Thanks. Maybe I did a dumb thing by overloading IOError and os.popen
      is actually catching that exception for purposes of its own. I'll
      try making a new exception.

      Comment

      Working...