Skip to content

Commit

Permalink
Remove unnecessary code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldoussoren committed Dec 6, 2023
1 parent 24746fb commit 673672f
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions Lib/test/support/os_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,20 +591,17 @@ def __fspath__(self):
def fd_count():
"""Count the number of open file descriptors.
"""
fd_path = None
if sys.platform.startswith(('linux', 'freebsd', 'emscripten')):
try:
names = os.listdir("/proc/self/fd")
# Subtract one because listdir() internally opens a file
# descriptor to list the content of the /proc/self/fd/ directory.
return len(names) - 1
except FileNotFoundError:
pass
fd_path = "/proc/self/fd"
elif sys.platform == "darwin":
fd_path = "/dev/fd"

if sys.platform == 'darwin':
if fd_path is not None:
try:
names = os.listdir("/dev/fd")
names = os.listdir(fd_path)
# Subtract one because listdir() internally opens a file
# descriptor to list the content of the /dev/fd directory.
# descriptor to list the content of the directory.
return len(names) - 1
except FileNotFoundError:
pass
Expand Down

0 comments on commit 673672f

Please sign in to comment.