Last active
July 18, 2019 01:22
-
-
Save HelloZeroNet/d1f2d5424f4026def8558cc11ed2fa68 to your computer and use it in GitHub Desktop.
Test opened socket and file limit in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import ctypes, socket, time | |
import gevent.monkey | |
gevent.monkey.patch_all() | |
print("Max stdio:", ctypes.cdll.msvcr100._getmaxstdio()) | |
# print("Max stdio:", ctypes.cdll.msvcr100._setmaxstdio(2048)) | |
# via https://github.com/ariccio/DuplicateFileFinder/blob/master/py_duplicate_pysummer.py | |
print("Testing files...") | |
files = [] | |
for i in range(64000): | |
try: | |
files.append(open("test_limit.py")) | |
except Exception as err: | |
print("Error:", err) | |
break | |
print("Max:", len(files)) | |
del files | |
print("Testing sockets...") | |
sockets = [] | |
def handle(socket, address): | |
pass | |
import gevent.server | |
server = gevent.server.StreamServer(('127.0.0.1', 8800), handle) # creates a new server | |
gevent.spawn(server.start) # start accepting new connections | |
gevent.sleep(0.1) | |
for i in range(64000): | |
try: | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect(("127.0.0.1", 8800)) | |
sockets.append(s) | |
except Exception as err: | |
print("Error:", err) | |
break | |
print("Max:", len(sockets)) | |
del sockets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment