Run process with timeout

P at draigBrady.com P at draigBrady.com
Mon Oct 17 09:04:14 EDT 2005


Natan wrote:
> Hi.
> 
> I have a python script under linux where I poll many hundreds of
> interfaces with mrtg every 5 minutes. Today I create some threads and
> use os.system(command) to run the process, but some of them just hang.
> I would like to terminate the process after 15 seconds if it doesn't
> finish, but os.system() doesn't have any timeout parameter.
> 
> Can anyone help me on what can I use to do this?

The new subprocess module has that functionality.
If your python version doesn't have that you
could try my unix specific version:
http://www.pixelbeat.org/libs/subProcess.py

Pádraig.



More information about the Python-list mailing list