Files
swift-mirror/test/Inputs/timeout.py
Mike Ash 1b8c109f9f [Test] Make timeout.py signal an error when the timeout is hit.
Print an error message and exit with a non-zero code when we hit the timeout. This makes it clear when a test fails due to a timeout.
2024-08-21 10:24:56 -04:00

20 lines
463 B
Python

#!/uar/bin/env python3
import subprocess
import sys
def watchdog(command, timeout=None):
process = subprocess.Popen(command)
try:
process.communicate(timeout=timeout)
except subprocess.TimeoutExpired:
process.kill()
sys.exit(
'error: command timed out after {} seconds: {}'
.format(timeout, ' '.join(sys.argv[2:])))
if __name__ == '__main__':
watchdog(sys.argv[2:], timeout=float(sys.argv[1]))