473,608 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem: using signal.alarm() to stop a run-away os.system() command

I'm trying to use signal.alarm to stop a run-away os.system command.
Can anyone exlain the following behavior?

Given following the trivial program:

import os
import signal

def timeoutHandler( signum, frame):
print "Timeout"
raise ValueError
signal.signal(s ignal.SIGALRM, timeoutHandler)
signal.alarm(5)

os.system("yes" )

signal.alarm(0)
What I expect is that the Linux/UNIX 'yes' command (which runs until
terminated) would be stopped after 5 seconds, when the timeoutHandler
is called, thus raising a ValueError and terminating this example
program. Instead, the 'yes' command run until it is terminated (by,
say, a kill command), at which time the timeoutHandler is called. In
other words, the running of the 'yes' command acts like it is blocking
the SIGALRM signal until it terminates, at which time the SIGALRM
signal is raised. This is quite surprising, and totally defeats my
ability to catch a run-away process. Can anyone see what I'm doing
wrong?

Jul 19 '05 #1
0 1459

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

Similar topics

0
2099
by: Dave Harrison | last post by:
Ok before I start, please dont mail me telling me to use a more recent version of Python, I _would_ use 2.2.x but due to an existing framework all based on using 2.1.1 I have been specifically told to use 2.1.1 to avoid any crossover issues/problems. Thanks ;-) So ... Using gcc Im compiling Python2.1.1, and it configures quite reasonably, the ./configure is trascribed at the bottom of this email. now once I have done that I compile it...
5
2292
by: Klaus Neuner | last post by:
Hello, consider the following two programs: # (1) import sys, signal def alarm_handler(signum, frame): raise
0
1642
by: rh0dium | last post by:
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):
3
2480
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...
1
5295
by: xoinki | last post by:
hi experts, I need a little help in debugging this code.. would u pleeze kindly help me? here this program sends a datagram every 10 seconds and on reception it cheks whether the source IP is already written in file or not.. if it is not already entered into the file then a file is opened and that IP is entered. the problem is with this part.. if the filewrite() function is tested independently it is working but in this program...
3
1820
by: norm4h8 | last post by:
Hi! I have a question about how to create a process in such a way that it would terminate itself if its wated for input for too long. Here is the story. I have 2 different files, say R.c and S.c, which have a named pipe between them and send each other signals. R process starts first, it opens a named pipe and waits for S to connect. S connects to the pipe, writes something to it and sends the signal to R indicating that R can read....
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...
2
5471
by: responsible | last post by:
Hi, I am trying to convert a small piece of source code that was initially written for Linux to build under Windows. My main problem though is in two lines... 1. signal(SIGALRM, timeoutHandler); // set alarm signal handler 2. alarm (timeout); I am not sure what the best method is to handle those? Are there any constructs in Windows that will make the translation as painless as
1
1938
by: webotronics | last post by:
Hi, I need to add a timeout for external programs, as the external program sometimes never dies (it's a ClearQuest multisite call to the shipping server, that sometimes never ends, but simply hangs). I have three different ways of forking the call, but none works. I send the one I believe most in... use POSIX ":sys_wait_h"; my $loop = 1; $loop = $ARGV if defined $ARGV;
2
2524
by: Paul Rubin | last post by:
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)
0
8063
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
8002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8475
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6013
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
3962
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...
0
4024
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2474
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
1594
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1329
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.