diff options
author | Niklas Fiekas <niklas.fiekas@backscattering.de> | 2019-05-20 12:02:17 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-05-20 12:02:16 (GMT) |
commit | 9932fd91e878b740704ff599522e945a4bbe2ae1 (patch) | |
tree | 2aa24d867fc52f03e9312cd8617a12263f84c150 /Lib/asyncio | |
parent | 6d1c46746e17367caf8a24623cb5c9a9c4e3e036 (diff) | |
download | cpython-9932fd91e878b740704ff599522e945a4bbe2ae1.zip cpython-9932fd91e878b740704ff599522e945a4bbe2ae1.tar.gz cpython-9932fd91e878b740704ff599522e945a4bbe2ae1.tar.bz2 |
bpo-35721: Close socket pair if Popen in _UnixSubprocessTransport fails (GH-11553)
This slightly expands an existing test case `test_popen_error` to trigger a `ResourceWarning` and fixes it.
https://bugs.python.org/issue35721
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/unix_events.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 73d4bda..1aa3b39 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -757,12 +757,18 @@ class _UnixSubprocessTransport(base_subprocess.BaseSubprocessTransport): # other end). Notably this is needed on AIX, and works # just fine on other platforms. stdin, stdin_w = socket.socketpair() - self._proc = subprocess.Popen( - args, shell=shell, stdin=stdin, stdout=stdout, stderr=stderr, - universal_newlines=False, bufsize=bufsize, **kwargs) - if stdin_w is not None: - stdin.close() - self._proc.stdin = open(stdin_w.detach(), 'wb', buffering=bufsize) + try: + self._proc = subprocess.Popen( + args, shell=shell, stdin=stdin, stdout=stdout, stderr=stderr, + universal_newlines=False, bufsize=bufsize, **kwargs) + if stdin_w is not None: + stdin.close() + self._proc.stdin = open(stdin_w.detach(), 'wb', buffering=bufsize) + stdin_w = None + finally: + if stdin_w is not None: + stdin.close() + stdin_w.close() class AbstractChildWatcher: |