0

Possible Duplicate:
subprocess with timeout
Best way to launch a process and block until it is finished

I have a python code where I need to run a Linux command like "curl --user....". I need to run this command for 3600 seconds. After the 3600 seconds I need to kill the "Linux command process". How can I possibly do this?

def timeout_command(command, timeout):
    import os, datetime, time, signal
    start = datetime.datetime.now()
    time_pass = 0
    while (time_pass < timeout):
        process = os.system(command)
        now = datetime.datetime.now()
        time_pass = (now-start).seconds
        print time_pass

print timeout_command("curl --user...", 3600)
print "Other2"
print "Other3"

Any clues on how to kill this: "process = os.system(command)"?

Best Regards,

Community
  • 1
  • 1
André
  • 24,706
  • 43
  • 121
  • 178

1 Answers1

2

subprocess is elegant way. If you are using multiprocessing(you can launch a child process for every 3600 secs), use os.system("kill -9 + multiprocessing.current_process().pid) to kill child process after 3600 secs

sumnepy
  • 36
  • 1