Using Signal Handler to timeout an rsh call

Discussion in 'Python' started by rh0dium, Aug 22, 2005.

  1. rh0dium

    rh0dium Guest

    Hi all,

    I don't understand the signal module. I guess I understand what it
    does in principle but I can't figure out how to use it to timeout an
    external rsh command after a 5 seconds. Does anyone know how to do
    this.
    Here is what I have so far - which is largely based on the example on
    the man page..

    def handler(signum, frame):
    print 'Signal handler called with signal', signum
    raise IOError, "Couldn't open device!"


    for host in alive:
    try:
    # Set the signal handler and a 5-second alarm
    signal.signal(signal.SIGALRM, handler)
    signal.alarm(5)

    (out,results) = commands.getstatusoutput( "rsh %s uname
    -a" % host)

    signal.alarm(0) # Disable the alarm
    #self.logger.debug( "%s Connection to %s - %s" %
    (out,host,results))

    if out ==256:
    noaccess.append(host)
    del alive[host]
    break
    if out == 0:
    if re.search("SunOS",results):
    hosttype="sun"
    elif re.search("Linux",results):
    hosttype="linux"

    Can anyone point me in the right direction. Much appreciated!!
    rh0dium, Aug 22, 2005
    #1
    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. sc0ri0n

    disconnecting rsh session

    sc0ri0n, Feb 16, 2005, in forum: Perl
    Replies:
    1
    Views:
    545
    Jim Gibson
    Feb 16, 2005
  2. Replies:
    1
    Views:
    1,035
    Thomas Weidenfeller
    Apr 8, 2005
  3. David H
    Replies:
    0
    Views:
    478
    David H
    Dec 3, 2004
  4. Replies:
    16
    Views:
    737
    Martin Gregorie
    Jun 2, 2007
  5. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,279
    Brian Candler
    Oct 6, 2004
Loading...

Share This Page