Skip to content

Instantly share code, notes, and snippets.

@carlos-jenkins
Created September 6, 2019 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlos-jenkins/beba09db1e7b4639e7e37f33448d56ec to your computer and use it in GitHub Desktop.
Save carlos-jenkins/beba09db1e7b4639e7e37f33448d56ec to your computer and use it in GitHub Desktop.
Get and set the NOPEN limit (maximum number of open files)
from resource import RLIMIT_NOFILE, getrlimit, setrlimit
def setfilelimits(limit):
soft, hard = getrlimit(RLIMIT_NOFILE)
if limit > hard:
raise RuntimeError(
'Unable to raise open files limit to {}. '
'Hard limit is set to {}'.format(
limit, hard,
)
)
setrlimit(RLIMIT_NOFILE, (limit, hard))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment