Created
February 5, 2015 13:11
-
-
Save jossef/ab356497e0c78de2fc33 to your computer and use it in GitHub Desktop.
python subprocess with timeout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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