forked from ethanchewy/PythonBuddy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_killsubprocess.py
More file actions
34 lines (30 loc) · 1.09 KB
/
test_killsubprocess.py
File metadata and controls
34 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import sys, time
import subprocess
from rpython.tool.killsubprocess import killsubprocess
def waitdead(process):
for i in range(50):
time.sleep(0.1)
if process.poll() is not None:
break # ok
else:
raise AssertionError("the subprocess did not die within 5 seconds")
def test_killsubprocess():
popen = subprocess.Popen([sys.executable, '-c', 'raw_input()'],
stdin=subprocess.PIPE)
time.sleep(0.9)
assert popen.poll() is None
assert popen.poll() is None
killsubprocess(popen)
waitdead(popen)
def test_already_dead_but_no_poll():
popen = subprocess.Popen([sys.executable, '-c', 'pass'],
stdin=subprocess.PIPE)
time.sleep(3) # a safe margin to be sure the subprocess is already dead
killsubprocess(popen)
assert popen.poll() is not None
def test_already_dead_and_polled():
popen = subprocess.Popen([sys.executable, '-c', 'pass'],
stdin=subprocess.PIPE)
waitdead(popen)
killsubprocess(popen)
assert popen.poll() is not None