Files
swift-mirror/test/stdlib/timeout.py
Saleem Abdulrasool 6618ec17dd stdlib: replace shell script with python
Replace timeout.sh with timeout.py.  This makes it portable to other
platforms like Windows.
2018-12-11 17:28:39 -08:00

20 lines
373 B
Python

#!/uar/bin/env python
import subprocess
import sys
import threading
def watchdog(command, timeout=None):
process = subprocess.Popen(command)
timer = threading.Timer(timeout, process.kill)
try:
timer.start()
process.communicate()
finally:
timer.cancel()
if __name__ == '__main__':
watchdog(sys.argv[2:], timeout=sys.argv[1])