470,849 Members | 681 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

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 1352

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dave Harrison | last post: by
5 posts views Thread by Klaus Neuner | last post: by
reply views Thread by rh0dium | last post: by
3 posts views Thread by rh0dium | last post: by
7 posts views Thread by Adrian Casey | last post: by
2 posts views Thread by Paul Rubin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.