From a4f12b7c1aa1e76021130cb574475fc60cae3592 Mon Sep 17 00:00:00 2001 From: John Litborn <11260241+jakkdl@users.noreply.github.com> Date: Sun, 17 Sep 2023 10:07:42 +0200 Subject: [PATCH] Add comment and assertion to `pidfd_open` workaround (#2799) * add assertion check to os.pidfd_open on linux, clarifying it's for <3.9 and pypy --- trio/_subprocess.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/trio/_subprocess.py b/trio/_subprocess.py index 978f7e6188..5ade2d4dc7 100644 --- a/trio/_subprocess.py +++ b/trio/_subprocess.py @@ -49,6 +49,8 @@ def pidfd_open(fd: int, flags: int) -> int: from os import pidfd_open except ImportError: if sys.platform == "linux": + # This workaround is only needed on 3.8 and pypy + assert sys.version_info < (3, 9) or sys.implementation.name != "cpython" import ctypes _cdll_for_pidfd_open = ctypes.CDLL(None, use_errno=True) @@ -69,7 +71,7 @@ def pidfd_open(fd: int, flags: int) -> int: def pidfd_open(fd: int, flags: int) -> int: result = _cdll_for_pidfd_open.syscall(__NR_pidfd_open, fd, flags) - if result < 0: + if result < 0: # pragma: no cover err = ctypes.get_errno() raise OSError(err, os.strerror(err)) return result