Skip to content

Commit 1b8c109

Browse files
committed
[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.
1 parent e27f195 commit 1b8c109

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

test/Inputs/timeout.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
import subprocess
44
import sys
5-
import threading
65

76

87
def watchdog(command, timeout=None):
98
process = subprocess.Popen(command)
10-
timer = threading.Timer(timeout, process.kill)
119
try:
12-
timer.start()
13-
process.communicate()
14-
finally:
15-
timer.cancel()
10+
process.communicate(timeout=timeout)
11+
except subprocess.TimeoutExpired:
12+
process.kill()
13+
sys.exit(
14+
'error: command timed out after {} seconds: {}'
15+
.format(timeout, ' '.join(sys.argv[2:])))
1616

1717

1818
if __name__ == '__main__':

0 commit comments

Comments
 (0)