Create a process with a "time to live"
Fredrik Lundh
fredrik at pythonware.com
Fri Aug 15 14:03:10 EDT 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
the process.
(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/ )
</F>
More information about the Python-list
mailing list