SIGALRM problem

P

Paul Rubin

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
 
M

Mike Driscoll

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top