summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-01-06 00:14:09 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-01-06 00:14:09 (GMT)
commit43a85343649fda4d3f7b56d71bafd01ce88f0b99 (patch)
tree57853282b538674cda1efa8a564409b001dcda1a
parent2b014b37486bb92f1fd641b59f8b7fe8741e5351 (diff)
parentc447ba04e78a91c1febe7744b9e6cbcdd3e23360 (diff)
downloadcpython-43a85343649fda4d3f7b56d71bafd01ce88f0b99.zip
cpython-43a85343649fda4d3f7b56d71bafd01ce88f0b99.tar.gz
cpython-43a85343649fda4d3f7b56d71bafd01ce88f0b99.tar.bz2
Merge 3.4 (asyncio)
-rw-r--r--Lib/asyncio/subprocess.py3
-rw-r--r--Lib/test/test_asyncio/test_subprocess.py28
2 files changed, 30 insertions, 1 deletions
diff --git a/Lib/asyncio/subprocess.py b/Lib/asyncio/subprocess.py
index f6d6a14..a8ad03c 100644
--- a/Lib/asyncio/subprocess.py
+++ b/Lib/asyncio/subprocess.py
@@ -96,7 +96,8 @@ class SubprocessStreamProtocol(streams.FlowControlMixin,
returncode = self._transport.get_returncode()
while self._waiters:
waiter = self._waiters.popleft()
- waiter.set_result(returncode)
+ if not waiter.cancelled():
+ waiter.set_result(returncode)
class Process:
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index d82cbbf..dfe23be 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -223,6 +223,34 @@ class SubprocessMixin:
self.assertEqual(output.rstrip(), b'3')
self.assertEqual(exitcode, 0)
+ def test_cancel_process_wait(self):
+ # Issue #23140: cancel Process.wait()
+
+ @asyncio.coroutine
+ def wait_proc(proc, event):
+ event.set()
+ yield from proc.wait()
+
+ @asyncio.coroutine
+ def cancel_wait():
+ proc = yield from asyncio.create_subprocess_exec(
+ *PROGRAM_BLOCKED,
+ loop=self.loop)
+
+ # Create an internal future waiting on the process exit
+ event = asyncio.Event(loop=self.loop)
+ task = self.loop.create_task(wait_proc(proc, event))
+ yield from event.wait()
+
+ # Cancel the future
+ task.cancel()
+
+ # Kill the process and wait until it is done
+ proc.kill()
+ yield from proc.wait()
+
+ self.loop.run_until_complete(cancel_wait())
+
if sys.platform != 'win32':
# Unix