Skip to content

Commit

Permalink
Add comment and assertion to pidfd_open workaround (#2799)
Browse files Browse the repository at this point in the history
* add assertion check to os.pidfd_open on linux, clarifying it's for <3.9 and pypy
  • Loading branch information
jakkdl authored Sep 17, 2023
1 parent f86cbed commit a4f12b7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion trio/_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit a4f12b7

Please sign in to comment.