8000 Python issue #23347: send_signal(), terminate(), kill() don't check i… · python/asyncio@6c7490e · 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 6c7490e

Browse files
committed
Python issue #23347: 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.
1 parent d37a906 commit 6c7490e

File tree

2 files changed

+3
-20
lines changed

2 files changed

+3
-20
lines changed

asyncio/base_subprocess.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def _make_read_subprocess_pipe_proto(self, fd):
8484
raise NotImplementedError
8585

8686
def close(self):
87+
if self._closed:
88+
return
8789
self._closed = True
8890

8991
for proto in self._pipes.values():
@@ -100,8 +102,7 @@ def close(self):
100102
except ProcessLookupError:
101103
pass
102104

103-
# Don't clear the _proc reference yet because _post_init() may
104-
# still run
105+
# Don't clear the _proc reference yet: _post_init() may still run
105106

106107
# On Python 3.3 and older, objects with a destructor part of a reference
107108
# cycle are never destroyed. It's not more the case on Python 3.4 thanks
@@ -125,8 +126,6 @@ def get_pipe_transport(self, fd):
125126
return None
126127

127128
def _check_proc(self):
128-
if self._closed:
129-
raise ValueError("operation on closed transport")
130129
if self._proc is None:
131130
raise ProcessLookupError()
132131

tests/test_subprocess.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,6 @@ def create_transport(self, waiter=None):
4747
None, None, None, 0, waiter=waiter)
4848
return (transport, protocol)
4949

50-
def test_close(self):
51-
waiter = asyncio.Future(loop=self.loop)
52-
transport, protocol = self.create_transport(waiter)
53-
transport._process_exited(0)
54-
transport.close()
55-
56-
# The loop didn't run yet
57-
self.assertFalse(protocol.connection_made.called)
58-
59-
# methods must raise ProcessLookupError if the transport was closed
60-
self.assertRaises(ValueError, transport.send_signal, signal.SIGTERM)
61-
self.assertRaises(ValueError, transport.terminate)
62-
self.assertRaises(ValueError, transport.kill)
63-
64-
self.loop.run_until_complete(waiter)
65-
6650
def test_proc_exited(self):
6751
waiter = asyncio.Future(loop=self.loop)
6852
transport, protocol = self.create_transport(waiter)

0 commit comments

Comments
 (0)
0