From: Allison Karlitskaya Date: Sun, 24 Dec 2023 00:43:39 +0000 (+0100) Subject: gh-112800: Ignore PermissionError on SubprocessTransport.close() in asyncio (#112803) X-Git-Tag: v3.13.0a3~274 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0187a7e4ec9550a6e35dd06b26f22863520242ab;p=thirdparty%2FPython%2Fcpython.git gh-112800: Ignore PermissionError on SubprocessTransport.close() in asyncio (#112803) In case the spawned process is setuid, we may not be able to send signals to it, in which case our .kill() call will raise PermissionError. Ignore that in order to avoid .close() raising an exception. Hopefully the process will exit as a result of receiving EOF on its stdin. --- diff --git a/Lib/asyncio/base_subprocess.py b/Lib/asyncio/base_subprocess.py index 4c9b0dd5653c..6dbde2b696ad 100644 --- a/Lib/asyncio/base_subprocess.py +++ b/Lib/asyncio/base_subprocess.py @@ -115,7 +115,8 @@ class BaseSubprocessTransport(transports.SubprocessTransport): try: self._proc.kill() - except ProcessLookupError: + except (ProcessLookupError, PermissionError): + # the process may have already exited or may be running setuid pass # Don't clear the _proc reference yet: _post_init() may still run diff --git a/Misc/NEWS.d/next/Library/2023-12-06-16-01-33.gh-issue-112800.TNsGJ-.rst b/Misc/NEWS.d/next/Library/2023-12-06-16-01-33.gh-issue-112800.TNsGJ-.rst new file mode 100644 index 000000000000..e88eac169177 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-12-06-16-01-33.gh-issue-112800.TNsGJ-.rst @@ -0,0 +1,2 @@ +Fix :mod:`asyncio` ``SubprocessTransport.close()`` not to throw +``PermissionError`` when used with setuid executables.