473,606 Members | 2,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Signal Handler to timeout an rsh call

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(s ignal.SIGALRM, handler)
signal.alarm(5)

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

signal.alarm(0) # Disable the alarm
#self.logger.de bug( "%s Connection to %s - %s" %
(out,host,resul ts))

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

Can anyone point me in the right direction. Much appreciated!!

Aug 22 '05 #1
0 1640

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3952
by: Gary Robinson | last post by:
In some code we're writing we're making an assumption, and I'd like to confirm that the assumption is valid. Suppose a signal arrives while a file is being written, and the signal handler explicitly raises a SystemExit exception. My understanding is that the C-level I/O code will continue and the signal won't be processed until the end of the atomic python interpreter instruction that invoked that C code.
3
2479
by: rh0dium | last post by:
Hi all, Another newbie question. So you can't use signals on threads but you can use select. The reason I want to do this in the first place it I need a timeout. Fundamentally I want to run a command on another machine, but I need a timeout. I have to do this to a LOT of machines ( > 3000 ) and threading becomes necessary for timeliess. So I created a function which works with signals ( until you throw threading at it.. ) but I...
3
3512
by: Martin McCormick | last post by:
A C program contains several signal statements to remove a lock file if the program gets killed: /*Set up interrupt handler to catch ctrl-C so that lock file can be removed.*/ signal(SIGINT,crash); signal(SIGBUS,crash); signal(SIGSEGV,crash); This part works. Those signals cause the "crash.c" module to run and get rid of the lock. Is there a standard way to also print
4
2003
by: Eric Boutin | last post by:
Hi ! currently reading C docs, I think I'm reading docs about the stdc lib, but I'm not shure.. it talks about signals, does *all* OS implement the signal function, and use it well ? I mean.. I know Unixes do it, but what about windows ? does it implements all SIG* signal promptly ? Thanks ! -Eric Boutin
11
2945
by: Jackie | last post by:
Hi everyone, I'd like to know when and how signals are used (e.g. SIGFPE, SIGABRT, SIGTERM, SIGSEGV, SIGINT)? Thank you so much.
18
3897
by: Sven | last post by:
Hi, I found a strange behaviour when using the time() function from time.h. Sometimes when it is called, it does not show the correct time in seconds, but an initial value. This time seem to be the time when the program was started the first time. My platform is a DEC machine with Tru64 onboard. A possible explanation could be, that the time() function is called
7
11067
by: Adrian Casey | last post by:
I have a multi-threaded python application which uses pexpect to connect to multiple systems concurrently. Each thread within my application is a connection to a remote system. The problem is when one of the child threads runs a command which generates an unlimited amount of output. The classic example of this is the "yes" command. If you execute "pexpect.run('yes')", your cpu will sit at 100% forever. Here is a simple multi-threaded...
5
6635
by: david | last post by:
I'm developing a program that runs using an asyncore loop. Right now I can adequately terminate it using Control-C, but as things get refined I need a better way to stop it. I've developed another program that executes it as a child process using popen2.Popen4(). I was attempting to use signals to stop it (using os.kill()) but I keep running into a problem where sending the signal causes an infinite loop of printing the message...
9
5811
by: thagor2008 | last post by:
Is the behaviour of throwing exceptions in a unix signal handler defined? eg: void sighandler(int sig) { ... do something throw myobj; }
0
8031
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8315
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5971
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3945
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2452
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1309
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.