473,396 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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(signal.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 1448

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

Similar topics

0
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...
5
by: Klaus Neuner | last post by:
Hello, consider the following two programs: # (1) import sys, signal def alarm_handler(signum, frame): raise
0
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...
3
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...
1
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...
3
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...
7
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...
2
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,...
1
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...
2
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.