Skip to content

Instantly share code, notes, and snippets.

@HelloZeroNet
Last active March 5, 2016 12:34
Show Gist options
  • Save HelloZeroNet/d9bf888693e66a573815 to your computer and use it in GitHub Desktop.
Save HelloZeroNet/d9bf888693e66a573815 to your computer and use it in GitHub Desktop.
Test and change max open files limit
fdb = []
for i in xrange(10000):
try:
fdb.append(open('test_max.py', 'r'))
except Exception, err:
print "Max open files without changing settings: %s" % i
break
fdb = []
import sys
if sys.platform == "win32":
import win32file
print "Current maxstdio", win32file._getmaxstdio(), "Changing to 2048..."
win32file._setmaxstdio(2048)
else:
import resource
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
print "Current RLIMIT_NOFILE limit:", soft, hard, "Changing to 2048..."
resource.setrlimit(resource.RLIMIT_NOFILE, (2048, hard))
fdb = []
for i in xrange(10000):
try:
fdb.append(open('test_max.py', 'r'))
except Exception, err:
print "Max open files after changing settings: %s" % i
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment