Skip to content

Instantly share code, notes, and snippets.

@jossef
Created February 5, 2015 13:11
Show Gist options
  • Save jossef/ab356497e0c78de2fc33 to your computer and use it in GitHub Desktop.
Save jossef/ab356497e0c78de2fc33 to your computer and use it in GitHub Desktop.
python subprocess with timeout
def call(command, timeout=60):
process = None
def target():
global process
process = subprocess.Popen(command)
process.communicate()
thread = threading.Thread(target=target)
thread.start()
thread.join(timeout)
if thread.is_alive():
process.terminate()
thread.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment