After trying 1000 loop.create_datagram_endpoints() I'm getting this error:
(Note: It goes up to 249 before crashing.)
Traceback (most recent call last):
File "BLAgent.py", line 19, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/tulip/base_events.py", line 152, in run_until_complete
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/tulip/futures.py", line 240, in result
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/tulip/tasks.py", line 130, in _step
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/tulip/base_events.py", line 397, in create_datagram_endpoint
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/tulip/base_events.py", line 380, in create_datagram_endpoint
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/socket.py", line 94, in __init__
OSError: [Errno 24] Too many open files
I understand this might be an OS limit (After all I'm using OS X on a MacBook Pro and think there is a default 256 max file open limit), but after some checking:
Max Files Open:
$sysctl -a | grep files
kern.maxfiles = 12288
kern.maxfilesperproc = 10240
kern.maxfiles: 12288
kern.maxfilesperproc: 10240
kern.num_files: 1795
and further:
Max Sockets Open:
$ sysctl -a | grep somax
kern.ipc.somaxconn: 2048
So, I should theoretically be able to have ~12,000 file and ~2000 sockets open.
Is this just the limit of this small box or is there something else limiting this? (socket.py limit?)
Could anyone check this on a real server box?
Server Code is the example: udp_echo.py
Client code below:
#--------------------------------------------------------------------------------
#!/usr/bin/env python
"""Base Level Agent"""
import argparse
import sys
import tulip
import RPS
import functools
loop = tulip.get_event_loop()
for i in range(0,1000,1):
message = "Message " + str(i)
t = tulip.async(loop.create_datagram_endpoint(
functools.partial(RPS.RPS,message,i,i+1),
remote_addr = ('127.0.0.1',9999)))
loop.run_until_complete(t)
loop.run_forever()
#--------------------------------------------------------------------------------
#!/usr/bin/env python
import tulip
class RPS:
def __init__(self, message, id, poll_time = 5):
self.message = message
self.id = id
self.poll_time = poll_time
def connection_made(self, transport):
self.transport = transport
# inital call setup
loop = tulip.get_event_loop()
loop.call_soon(self.repeat_method)
def repeat_method(self):
print('polling')
print('sending "{}"'.format(self.message))
self.transport.sendto(self.message.encode())
print('waiting to receive')
# repeat again after xx seconds
loop = tulip.get_event_loop()
loop.call_later(self.poll_time,self.repeat_method)
def datagram_received(self, data, addr):
print("I'm %d" %
self.id)
print('received "{}"'.format(data.decode()))
#self.transport.close()
def connection_refused(self, exc):
print('Connection refused:', exc)
def connection_lost(self, exc):
print('closing transport', exc)
loop = tulip.get_event_loop()
loop.stop()