8000 rework · python/cpython@0b87f8d · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b87f8d

Browse files
rework
1 parent 7c10817 commit 0b87f8d

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

Lib/asyncio/base_subprocess.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -214,23 +214,15 @@ def _process_exited(self, returncode):
214214
# asyncio uses a child watcher: copy the status into the Popen
215215
# object. On Python 3.6, it is required to avoid a ResourceWarning.
216216
self._proc.returncode = returncode
217-
218-
def __process_exited():
219-
self._protocol.process_exited()
220-
# Since process exited, clear all pipes
221-
for proto in self._pipes.values():
222-
if proto is None:
223-
continue
224-
proto.pipe.close()
225-
# Call _wait waiters
226-
for waiter in self._exit_waiters:
227-
if not waiter.cancelled():
228-
waiter.set_result(self._returncode)
229-
self._exit_waiters = None
230-
231-
self._call(__process_exited)
217+
self._call(self._protocol.process_exited)
232218
self._try_finish()
233219

220+
# wake up futures waiting for wait()
221+
for waiter in self._exit_waiters:
222+
if not waiter.cancelled():
223+
waiter.set_result(returncode)
224+
self._exit_waiters = None
225+
234226
async def _wait(self):
235227
"""Wait until the process exit and return the process return code.
236228
@@ -260,7 +252,6 @@ def _call_connection_lost(self, exc):
260252
self._protocol = None
261253

262254

263-
264255
class WriteSubprocessPipeProto(protocols.BaseProtocol):
265256

266257
def __init__(self, proc, fd):

Lib/asyncio/subprocess.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ def process_exited(self):
103103
self._maybe_close_transport()
104104

105105
def _maybe_close_transport(self):
106-
if len(self._pipe_fds) == 0 and self._process_exited:
106+
# Since process already exited
107+
# clear all the pipes and close transport
108+
if self._process_exited and self._transport:
107109
self._transport.close()
108110
self._transport = None
109111

0 commit comments

Comments
 (0)
0