Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > SIGALRM problem

Reply
Thread Tools

SIGALRM problem

 
 
Paul Rubin
Guest
Posts: n/a
 
      10-13-2008
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
 
Reply With Quote
 
 
 
 
Mike Driscoll
Guest
Posts: n/a
 
      10-13-2008
On Oct 13, 11:45*am, Paul Rubin <http://(E-Mail Removed)> 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/pyt...st/217530.html

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

Mike
 
Reply With Quote
 
 
 
 
Paul Rubin
Guest
Posts: n/a
 
      10-13-2008
Mike Driscoll <(E-Mail Removed)> writes:
> http://mail.python.org/pipermail/pyt...st/217530.html
> It's old, but it looks ok...


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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SIGALRM in a class member? Ron Eggler C++ 8 08-14-2008 08:05 AM
Is SIGALRM getting masked ??? apoorva.groups@gmail.com C Programming 1 12-30-2007 10:08 PM
Catching SIGALRM in a thread Samuel Perl Misc 7 05-23-2007 09:55 PM
SIGALRM available? Guillaume Marcais Ruby 2 02-15-2005 02:43 PM
timeouts with threads and SIGALRM Eric Schwartz Ruby 11 08-19-2004 11:57 PM



Advertisments