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

Commita77c0ff

Browse files
committed
handle asynchronous exceptions when creating SubprocessTransport
1 parent71cf406 commita77c0ff

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
@@ -25,6 +25,7 @@ def __init__(self, loop, protocol, args, shell,
2525
self._pending_calls=collections.deque()
2626
self._pipes= {}
2727
self._finished=False
28+
self._failed_before_start=False
2829

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

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

‎asyncio/unix_events.py‎

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

732732

733733
class_UnixSubprocessTransport(base_subprocess.BaseSubprocessTransport):
734-
def__init__(self,*args,**kwargs):
735-
super().__init__(*args,**kwargs)
736-
self._failed_before_exec=False
737-
738734
@coroutine
739735
def_start(self,args,shell,stdin,stdout,stderr,bufsize,**kwargs):
740736
withevents.get_child_watcher()aswatcher:
@@ -760,7 +756,7 @@ def _start(self, args, shell, stdin, stdout, stderr, bufsize, **kwargs):
760756
universal_newlines=False,bufsize=bufsize,**kwargs)
761757
yieldfromexec_waiter
762758
except:
763-
self._failed_before_exec=True
759+
self._failed_before_start=True
764760
# TODO stdin is probably closed by proc, but what about stdin_w
765761
# so far? check this
766762
ifstdin_wisnotNone:
@@ -776,17 +772,6 @@ def _start(self, args, shell, stdin, stdout, stderr, bufsize, **kwargs):
776772
def_child_watcher_callback(self,pid,returncode):
777773
self._loop.call_soon_threadsafe(self._process_exited,returncode)
778774

779-
@coroutine
780-
def_wait(self):
781-
ifself._failed_before_exec:
782-
# let loop._make_subprocess_transport() call transport._wait() when
783-
# an excpetion is raised asynchronously during the setup of the
784-
# transport, which garantees that necessary cleanup will be
785-
# performed
786-
return
787-
else:
788-
return (yieldfromsuper()._wait())
789-
790775

791776
classAbstractChildWatcher:
792777
"""Abstract base class for monitoring child processes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp