diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-01-14 02:09:23 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-01-14 02:09:23 +0100 |
commit | 5d03db872a37bd1122d76a75eafd3d59456d2ea1 (patch) | |
tree | b0ccab0e8bcbfbc6aa979d7c58a6bf5a0a4f4022 | |
parent | 14ddd5ec299dcd41ec5d856ec919515bc6a9d08d (diff) | |
download | trollius-5d03db872a37bd1122d76a75eafd3d59456d2ea1.tar.gz |
Python issue #23173: Fix SubprocessStreamProtocol.connection_made() to handle
cancelled waiter.
Add unit test cancelling subprocess methods.
-rw-r--r-- | asyncio/subprocess.py | 4 | ||||
-rw-r--r-- | tests/test_subprocess.py | 36 |
2 files changed, 39 insertions, 1 deletions
diff --git a/asyncio/subprocess.py b/asyncio/subprocess.py index d83442e..a028339 100644 --- a/asyncio/subprocess.py +++ b/asyncio/subprocess.py @@ -60,7 +60,9 @@ class SubprocessStreamProtocol(streams.FlowControlMixin, protocol=self, reader=None, loop=self._loop) - self.waiter.set_result(None) + + if not self.waiter.cancelled(): + self.waiter.set_result(None) def pipe_data_received(self, fd, data): if fd == 1: diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py index 5fc1dc0..b2f1b95 100644 --- a/tests/test_subprocess.py +++ b/tests/test_subprocess.py @@ -251,6 +251,42 @@ class SubprocessMixin: self.loop.run_until_complete(cancel_wait()) + def test_cancel_make_subprocess_transport_exec(self): + @asyncio.coroutine + def cancel_make_transport(): + coro = asyncio.create_subprocess_exec(*PROGRAM_BLOCKED, + loop=self.loop) + task = self.loop.create_task(coro) + + self.loop.call_soon(task.cancel) + try: + yield from task + except asyncio.CancelledError: + pass + + # ignore the log: + # "Exception during subprocess creation, kill the subprocess" + with test_utils.disable_logger(): + self.loop.run_until_complete(cancel_make_transport()) + + def test_cancel_post_init(self): + @asyncio.coroutine + def cancel_make_transport(): + coro = self.loop.subprocess_exec(asyncio.SubprocessProtocol, + *PROGRAM_BLOCKED) + task = self.loop.create_task(coro) + + self.loop.call_soon(task.cancel) + try: + yield from task + except asyncio.CancelledError: + pass + + # ignore the log: + # "Exception during subprocess creation, kill the subprocess" + with test_utils.disable_logger(): + self.loop.run_until_complete(cancel_make_transport()) + if sys.platform != 'win32': # Unix |