Using Signal Handler to timeout an rsh call

R

rh0dium

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!!
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top