Create a process with a "time to live"
fredrik at pythonware.com
Fri Aug 15 20:03:10 CEST 2008
Carl J. Van Arsdall wrote:
> I want to create a process that would "expire" if it didn't complete in
> a set amount of time. I don't seem to see any timeout values to pass
> os.system - does anyone know of a good way to do this?
> So far all I can think of is some kind of watchdog thread - but that
> seems like overkill to do such a simple thing.
simple approach: use subprocess.Popen to fork off the external command,
then sleep for a short while, check if it's done, sleep a little longer
if it hasn't, etc. when you've waited long enough, use os.kill to kill
(if you want to terminate a function in your own program, you can use
the alarm signal. see e.g. http://code.activestate.com/recipes/307871/ )
More information about the Python-list