Skip to content

Commit

Permalink
RF limiting within get_fdmax into something more sensible
Browse files Browse the repository at this point in the history
  • Loading branch information
yarikoptic committed Nov 21, 2024
1 parent 18718b2 commit 35c3ae1
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 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,36 +101,34 @@ def get_fdmax(default=None):
descriptor limit.
"""
# Some system might be "mis"configured and allow for ulimit -n
# of e.g. 1073741816 which would be infeasible to sweep through.
def _get_fdmax():
try:
return os.sysconf('SC_OPEN_MAX')
except:
pass

try:
fdmax = os.sysconf('SC_OPEN_MAX')
except:
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
return fdmax

value = _get_fdmax()
if value != default and value >= 1e5 :
# 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
import warnings
if default:
new_value = default
msg = "default"
fdmax_limited = default
msg = "the default"
else:
new_value = 10000
msg = "new smaller"
fdmax_limited = 10000
msg = "a new smaller"
warnings.warn(UserWarning(
f"System set max number of open files is way too high and set to {value}."
f"Will use {msg} value of {new_value}"))
return new_value
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 value
return fdmax


def uniq(it):
Expand Down

0 comments on commit 35c3ae1

Please sign in to comment.