system call that is killed after n seconds if not finished

Jaroslav Dobrek jaroslav.dobrek at gmail.com
Mon Apr 16 10:51:03 EDT 2012


Hello,

I would like to execute shell commands, but only if their execution
time is not longer than n seconds. Like so:

monitor(os.system("do_something"), 5)

I.e. the command do_somthing should be executed by the operating
system. If the call has not finished after 5 seconds, the process
should be killed.

How could this be done?

Jaroslav



More information about the Python-list mailing list