Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
/asyncioPublic archive

Commit4ba3e5b

Browse files
committed
handle asynchronous exceptions when creating SubprocessTransport
1 parentd808954 commit4ba3e5b

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

‎asyncio/base_subprocess.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, loop, protocol, args, shell,
2626
self._pending_calls=collections.deque()
2727
self._pipes= {}
2828
self._finished=False
29+
self._failed_before_start=False
2930

3031
ifstdin==subprocess.PIPE:
3132
self._pipes[0]=None
@@ -47,7 +48,12 @@ def _create_child(self, waiter, args, shell, stdin, stdout, stderr,
4748
start=self._start(args=args,shell=shell,stdin=stdin,
4849
stdout=stdout,stderr=stderr,
4950
bufsize=bufsize,**start_kwargs)
51+
except:
52+
self._failed_before_start=True
53+
self.close()
54+
raise
5055

56+
try:
5157
ifstartisnotNone:
5258
# _start is not required to be a coroutine
5359
yieldfromstart
@@ -255,6 +261,12 @@ def _wait(self):
255261
"""Wait until the process exit and return the process return code.
256262
257263
This method is a coroutine."""
264+
ifself._failed_before_start:
265+
# Let loop._make_subprocess_transport() call transport._wait() when
266+
# an exception is raised asynchronously during the setup of the
267+
# transport, it garantees that necessary cleanup will be performed.
268+
return
269+
258270
ifself._returncodeisnotNone:
259271
returnself._returncode
260272

‎asyncio/unix_events.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,6 @@ def _check_exec_result(self, pid, returncode, orig_executable, cwd,
713713

714714

715715
class_UnixSubprocessTransport(base_subprocess.BaseSubprocessTransport):
716-
def__init__(self,*args,**kwargs):
717-
super().__init__(*args,**kwargs)
718-
self._failed_before_exec=False
719-
720716
@coroutine
721717
def_start(self,args,shell,stdin,stdout,stderr,bufsize,**kwargs):
722718
withevents.get_child_watcher()aswatcher:
@@ -742,7 +738,7 @@ def _start(self, args, shell, stdin, stdout, stderr, bufsize, **kwargs):
742738
universal_newlines=False,bufsize=bufsize,**kwargs)
743739
yieldfromexec_waiter
744740
except:
745-
self._failed_before_exec=True
741+
self._failed_before_start=True
746742
# TODO stdin is probably closed by proc, but what about stdin_w
747743
# so far? check this
748744
ifstdin_wisnotNone:
@@ -758,17 +754,6 @@ def _start(self, args, shell, stdin, stdout, stderr, bufsize, **kwargs):
758754
def_child_watcher_callback(self,pid,returncode):
759755
self._loop.call_soon_threadsafe(self._process_exited,returncode)
760756

761-
@coroutine
762-
def_wait(self):
763-
ifself._failed_before_exec:
764-
# let loop._make_subprocess_transport() call transport._wait() when
765-
# an excpetion is raised asynchronously during the setup of the
766-
# transport, which garantees that necessary cleanup will be
767-
# performed
768-
return
769-
else:
770-
return (yieldfromsuper()._wait())
771-
772757

773758
classAbstractChildWatcher:
774759
"""Abstract base class for monitoring child processes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp