Skip to content

Commit

Permalink
pythongh-124213: Fix incorrect context manager use in in_systemd_nspa…
Browse files Browse the repository at this point in the history
…wn_sync_suppressed()

Fix the incorrect use of `os.open()` result as a context manager,
while it is actually a numeric file descriptor.

I have missed the problem, because in the original version the
`os.open()` call would always fail, and I failed to test the final
version in all possible scenarios properly.
  • Loading branch information
mgorny committed Oct 2, 2024
1 parent 595a563 commit 5c3c6bd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2907,10 +2907,11 @@ def in_systemd_nspawn_sync_suppressed() -> bool:
# trigger EINVAL. Otherwise, ENOENT will be given instead.
import errno
try:
with os.open(__file__, os.O_RDONLY | os.O_SYNC):
pass
fd = os.open(__file__, os.O_RDONLY | os.O_SYNC)
except OSError as err:
if err.errno == errno.EINVAL:
return True
else:
os.close(fd)

return False

0 comments on commit 5c3c6bd

Please sign in to comment.