Skip to content

Commit 8d7d257

Browse files
authored
gh-124213: Fix incorrect context manager use in in_systemd_nspawn_sync_suppressed() (#124892)
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.
1 parent c2ba931 commit 8d7d257

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Lib/test/support/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,10 +2907,11 @@ def in_systemd_nspawn_sync_suppressed() -> bool:
29072907
# trigger EINVAL. Otherwise, ENOENT will be given instead.
29082908
import errno
29092909
try:
2910-
with os.open(__file__, os.O_RDONLY | os.O_SYNC):
2911-
pass
2910+
fd = os.open(__file__, os.O_RDONLY | os.O_SYNC)
29122911
except OSError as err:
29132912
if err.errno == errno.EINVAL:
29142913
return True
2914+
else:
2915+
os.close(fd)
29152916

29162917
return False

0 commit comments

Comments
 (0)