diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-01-30 00:20:44 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-01-30 00:20:44 (GMT) |
commit | f2e43cbbd4b9325da638a6b45b52e766ca91b131 (patch) | |
tree | 3455f9db0834188f6f2450f4d2ddb3490e73734e /Lib | |
parent | 1077dee4575ccc43c10515de50d7c100d6ce9455 (diff) | |
download | cpython-f2e43cbbd4b9325da638a6b45b52e766ca91b131.zip cpython-f2e43cbbd4b9325da638a6b45b52e766ca91b131.tar.gz cpython-f2e43cbbd4b9325da638a6b45b52e766ca91b131.tar.bz2 |
Issue #23347, asyncio: send_signal(), terminate(), kill() don't check if the
transport was closed. The check broken a Tulip example and this limitation is
arbitrary. Check if _proc is None should be enough.
Enhance also close(): do nothing when called the second time.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/asyncio/base_subprocess.py | 7 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_subprocess.py | 16 |
2 files changed, 3 insertions, 20 deletions
diff --git a/Lib/asyncio/base_subprocess.py b/Lib/asyncio/base_subprocess.py index 70676ab..02b9e89 100644 --- a/Lib/asyncio/base_subprocess.py +++ b/Lib/asyncio/base_subprocess.py @@ -84,6 +84,8 @@ class BaseSubprocessTransport(transports.SubprocessTransport): raise NotImplementedError def close(self): + if self._closed: + return self._closed = True for proto in self._pipes.values(): @@ -100,8 +102,7 @@ class BaseSubprocessTransport(transports.SubprocessTransport): except ProcessLookupError: pass - # Don't clear the _proc reference yet because _post_init() may - # still run + # Don't clear the _proc reference yet: _post_init() may still run # On Python 3.3 and older, objects with a destructor part of a reference # cycle are never destroyed. It's not more the case on Python 3.4 thanks @@ -125,8 +126,6 @@ class BaseSubprocessTransport(transports.SubprocessTransport): return None def _check_proc(self): - if self._closed: - raise ValueError("operation on closed transport") if self._proc is None: raise ProcessLookupError() diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py index d4b71b7..b467b04 100644 --- a/Lib/test/test_asyncio/test_subprocess.py +++ b/Lib/test/test_asyncio/test_subprocess.py @@ -47,22 +47,6 @@ class SubprocessTransportTests(test_utils.TestCase): None, None, None, 0, waiter=waiter) return (transport, protocol) - def test_close(self): - waiter = asyncio.Future(loop=self.loop) - transport, protocol = self.create_transport(waiter) - transport._process_exited(0) - transport.close() - - # The loop didn't run yet - self.assertFalse(protocol.connection_made.called) - - # methods must raise ProcessLookupError if the transport was closed - self.assertRaises(ValueError, transport.send_signal, signal.SIGTERM) - self.assertRaises(ValueError, transport.terminate) - self.assertRaises(ValueError, transport.kill) - - self.loop.run_until_complete(waiter) - def test_proc_exited(self): waiter = asyncio.Future(loop=self.loop) transport, protocol = self.create_transport(waiter) |