Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cf95bef

Browse filesBrowse files
committed
fix subprocesses
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
1 parent 179579a commit cf95bef
Copy full SHA for cf95bef

File tree

1 file changed

+35
-0
lines changed
Filter options

1 file changed

+35
-0
lines changed

‎extra_tests/snippets/stdlib_subprocess.py

Copy file name to clipboardExpand all lines: extra_tests/snippets/stdlib_subprocess.py
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,43 @@ def sleep(secs):
2727
assert p.poll() == 0
2828
assert p.returncode == 0
2929

30+
p = subprocess.Popen(sleep(2))
31+
32+
assert p.poll() is None
33+
34+
with assert_raises(subprocess.TimeoutExpired):
35+
assert p.wait(1)
36+
37+
p.wait()
38+
39+
assert p.returncode == 0
40+
3041
p = subprocess.Popen(echo("test"), stdout=subprocess.PIPE)
3142
p.wait()
3243

3344

3445
assert p.stdout.read().strip() == b"test"
46+
47+
p = subprocess.Popen(sleep(2))
48+
p.terminate()
49+
p.wait()
50+
if is_unix:
51+
assert p.returncode == -signal.SIGTERM
52+
else:
53+
assert p.returncode == 1
54+
55+
p = subprocess.Popen(sleep(2))
56+
p.kill()
57+
p.wait()
58+
if is_unix:
59+
assert p.returncode == -signal.SIGKILL
60+
else:
61+
assert p.returncode == 1
62+
63+
p = subprocess.Popen(echo("test"), stdout=subprocess.PIPE)
64+
(stdout, stderr) = p.communicate()
65+
assert stdout.strip() == b"test"
66+
67+
p = subprocess.Popen(sleep(5), stdout=subprocess.PIPE)
68+
with assert_raises(subprocess.TimeoutExpired):
69+
p.communicate(timeout=1)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.