Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BF: restrict value of get_fdmax #417

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions billiard/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import subprocess
import sys
import warnings

from itertools import zip_longest

Expand Down Expand Up @@ -100,16 +101,34 @@ def get_fdmax(default=None):
descriptor limit.

"""

try:
return os.sysconf('SC_OPEN_MAX')
fdmax = os.sysconf('SC_OPEN_MAX')
except:
pass
if resource is None: # Windows
return default
fdmax = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
if fdmax == resource.RLIM_INFINITY:
return default
return fdmax
fdmax = None

if not fdmax:
if resource is None: # Windows
return default
fdmax = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
if fdmax == resource.RLIM_INFINITY:
return default
# Some system might be "mis"configured and allow for ulimit -n
# of e.g. 1073741816 which would be infeasible to sweep through.
if fdmax >= 1e5:
# limiting value is ad-hoc and already more than sensible
if default:
fdmax_limited = default
msg = "the default"
else:
fdmax_limited = 10000
msg = "a new smaller"
warnings.warn(UserWarning(
f"System set max number of open files ({fdmax}) is way too high. "
f"Will use {msg} value of {fdmax_limited}"))
return fdmax_limited
else:
return fdmax


def uniq(it):
Expand Down
Loading