Skip to content

Instantly share code, notes, and snippets.

@sudocurse
Last active October 22, 2019 06:58
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 sudocurse/a6f3b8f4fb1f55b1dfd2ec44fb80410a to your computer and use it in GitHub Desktop.
Save sudocurse/a6f3b8f4fb1f55b1dfd2ec44fb80410a to your computer and use it in GitHub Desktop.
macos default fd ulimit is 256. why do i see 252?
import tempfile
files = []
while True:
try:
file = tempfile.TemporaryFile()
print("Created file:", file, file.name)
files.append(file)
except OSError:
print("Total: {}".format(len(files)))
break
for x in files:
x.close()
@sudocurse
Copy link
Author

sudocurse commented Oct 15, 2019

10283 ◯  python fd.py
('Created file:', <open file '<fdopen>', mode 'w+b' at 0x10b3725d0>, '<fdopen>')
...
('Created file:', <open file '<fdopen>', mode 'w+b' at 0x10b3fcc00>, '<fdopen>')
Total: 252

@sudocurse
Copy link
Author

weeeirdddd

import resource

print("Max for process:", resource.RLIMIT_NOFILE) # maximum number of open file descriptors for the current process
print("Max for process:", resource.RLIMIT_OFILE)    # The BSD name for RLIMIT_NOFILE.
('Max for process:', 8)
AttributeError: 'module' object has no attribute 'RLIMIT_OFILE'

@sudocurse
Copy link
Author

oh but when i try it in python 3, it starts at 3:

10292 ◯  python3 fd.py
Created file: <_io.BufferedRandom name=3> 3
Created file: <_io.BufferedRandom name=4> 4
Created file: <_io.BufferedRandom name=5> 5
...
Created file: <_io.BufferedRandom name=254> 254
Created file: <_io.BufferedRandom name=255> 255
Total: 253

It gets one additional file in the count somehow

(this is 3.6) python 3 still gives me

Max for process: 8
Traceback (most recent call last):
  File "fd.py", line 16, in <module>
AttributeError: module 'resource' has no attribute 'RLIMIT_OFILE'

@sudocurse
Copy link
Author

sudocurse commented Oct 15, 2019

lolololol real dingus hours right here, these look and act like enums. here's how i should be doing it:

print("Max for process:", resource.getrlimit(resource.RLIMIT_NOFILE))
print("Max for process:", resource.getrlimit(resource.RLIMIT_OFILE))
Max for process: (256, 9223372036854775807)
Traceback (most recent call last):
  File "fd.py", line 16, in <module>
AttributeError: module 'resource' has no attribute 'RLIMIT_OFILE'

I wonder what 9223372036854775807 is 2^64-1. that tuple output is (soft, hard) limits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment