Skip to content

Commit 694c202

Browse files
authored
Merge pull request #76009 from mikeash/test-timeout-error-message
[Test] Make timeout.py signal an error when the timeout is hit.
2 parents b6a0162 + 1b8c109 commit 694c202

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)