8000 Fix a ResourceWarning in the shell example · python/asyncio@ab5d83c · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Commit ab5d83c

Browse files
committed
Fix a ResourceWarning in the shell example
Kill the process on timeout: don't keep a running process in the backgroud!
1 parent 6c7490e commit ab5d83c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

examples/shell.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ def ls(loop):
3636

3737
@asyncio.coroutine
3838
def test_call(*args, timeout=None):
39+
proc = yield from asyncio.create_subprocess_exec(*args)
3940
try:
40-
proc = yield from asyncio.create_subprocess_exec(*args)
4141
exitcode = yield from asyncio.wait_for(proc.wait(), timeout)
4242
print("%s: exit code %s" % (' '.join(args), exitcode))
4343
except asyncio.TimeoutError:
4444
print("timeout! (%.1f sec)" % timeout)
45+
proc.kill()
46+
yield from proc.wait()
4547

4648
loop = asyncio.get_event_loop()
4749
loop.run_until_complete(cat(loop))

0 commit comments

Comments
 (0)
0