https://github.com/python/cpython/commit/20ffdf7c7ca81fe4a4752aa621a82fd60e8d2e3b
commit: 20ffdf7c7ca81fe4a4752aa621a82fd60e8d2e3b
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2026-10-22T08:44:11Z
summary:
[3.14] On FreeBSD, use /dev/fd/ in fd_count() if it's mounted (GH-160210)
(#160221)
On FreeBSD, use /dev/fd/ in fd_count() if it's mounted (GH-160210)
fd_count() can now use /dev/fd/ fdescfs file system if it's mounted,
which is not the case by default. Otherwise, call os.dup(fd) in a
loop which is slow since os.sysconf("SC_OPEN_MAX") is larger than
200,000 by default.
(cherry picked from commit 226ca06ce8474d19fc26ff2568268a3c99c84d1c)
Co-authored-by: Victor Stinner <[email protected]>
files:
M Lib/test/support/os_helper.py
diff --git a/Lib/test/support/os_helper.py b/Lib/test/support/os_helper.py
index 36d2fa94c61d4f4..c1153856114b9b7 100644
--- a/Lib/test/support/os_helper.py
+++ b/Lib/test/support/os_helper.py
@@ -685,6 +685,24 @@ def fd_count():
except FileNotFoundError:
pass
+ if sys.platform == "freebsd" and fd_count._dev_fd_mounted:
+ # Check if /dev/fd/ fdescfs file system is mounted. By default, it's
+ # not mounted and /dev/fd/ always contains 3 files (0, 1, 2).
+ try:
+ dirfd = os.open("/dev/fd", os.O_RDONLY)
+ try:
+ if os.path.exists(f"/dev/fd/{dirfd}"):
+ names = list(os.scandir(dirfd))
+ # Don't count dirfd
+ return len(names) - 1
+ else:
+ # fdescfs is not mounted
+ fd_count._dev_fd_mounted = False
+ finally:
+ os.close(dirfd)
+ except FileNotFoundError:
+ pass
+
MAXFD = 256
if hasattr(os, 'sysconf'):
try:
@@ -732,6 +750,9 @@ def fd_count():
return count
+# On FreeBSD, flag set to False if /dev/fd/ is not mounted as fdescfs
+fd_count._dev_fd_mounted = True
+
if hasattr(os, "umask"):
@contextlib.contextmanager
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]