opensistemas-hub / osbrain

osBrain - A general-purpose multi-agent system module written in Python
https://osbrain.readthedocs.io/en/stable/
Apache License 2.0
175 stars 43 forks source link

Too many open files error #309

Closed amitection closed 6 years ago

amitection commented 6 years ago

I have a REPLY Agent bound to a particular communication channel

agent1.bind('REP', alias=str('request_'+agentname), handler=request_handler)

The handler does some processing and sends a reply.

On the other hand, the client agent (REQ) fetches a Proxy for this agent via the name server and send a message to this agent --

this_agent <- initialized somewher

agent_proxy = ns.proxy(name = remote_agent_name, timeout=0.5)
agent_proxy_addr = agent_proxy.addr(alias=str('request_'+remote_agent_name))

resp = send_message(agent = this_agent, server_addr = agent_proxy_addr, alias = str('request_'+remote_agent_name), message = "Some Message")

def send_message(agent, agent_proxy_addr, alias,  message):
    agent.connect(server=server_addr, alias=alias)
    agent.send(alias, message=message)
    reply = agent.recv(alias)
    agent.log_info("Recieved: "+str(reply))
    agent.close(alias=alias)
    return reply

The problem is I soon run out of sockets with this method. Am I doing something wrong?

StackTrace

---------------------------------------------------
 EXCEPTION <class 'zmq.error.ZMQError'>: Too many open files
 Extended stacktrace follows (most recent call last)
----------------------------------------------------
File "/usr/local/lib/python3.5/dist-packages/osbrain/proxy.py", line 219, in Proxy._pyroInvoke
Source code:
    methodname, args, kwargs, flags, objectId)
----------------------------------------------------
File "/usr/local/lib/python3.5/dist-packages/osbrain/proxy.py", line 262, in Proxy._remote_call
Source code:
    flags=flags, objectId=objectId)
Local values:
    __class__ = <class 'osbrain.proxy.Proxy'>
    args = ()
    flags = 0
    kwargs = {'alias': 'energy_request_Charlie'}
    methodname = 'addr'
    objectId = None
    safe_args = ['addr']
    self = <osbrain.proxy.Proxy at 0x7f446d714048; connected IPv4; for PYRONAME:Charlie@127.0.0.1:10000>
        self._next_oneway = False
        self._pyroAttrs = set()
        self._pyroSerializer = None
        self._Proxy__pyroTimeout = 0.0
        self._pyroHandshake = 'hello'
        self._pyroMethods = {'run', 'raise_exception', 'bind', 'on_init', 'addr', 'log_warning', 'send_recv', 'each
', 'set_method', 'log_debug', 'set_attr', 'subscribe', 'log_error', 'close', 'kill', 'execute_as_method', 'ping', '
has_socket', 'close_all', 'idle', 'safe_call', 'connect', 'unsubscribe', 'execute_as_function', 'is_running', 'log_
info', 'shutdown', 'stop', 'list_timers', 'send', 'after', 'recv', 'stop_all_timers', 'set_logger', 'before_loop', 
'stop_timer', 'get_attr'}

self._Proxy__async = False
        self._pyroRawWireResponse = False
        self._pyroMaxRetries = 0
        self._Proxy__pyroHmacKey = None
        self._pyroSeq = 2
        self._default_safe = True
        self._pyroOneway = {'run'}
        self._pyroUri = <Pyro4.core.URI at 0x7f446d6cf5c0; PYRONAME:Charlie@127.0.0.1:10000>
        self._safe = True
        self._pyroConnection = <Pyro4.socketutil.SocketConnection object at 0x7f446d6cfa90>
        self._Proxy__pyroConnLock = <unlocked _thread.RLock object owner=0 count=0 at 0x7f44a144a9c0>

---------------------------------------------------
File "/usr/local/lib/python3.5/dist-packages/Pyro4/core.py", line 476, in Proxy._pyroInvoke
Source code:
    raise data  # if you see this in your traceback, you should probably inspect the remote traceback as well
Local values:
    annotations = {}
    compressed = False
    data = ZMQError('Too many open files')
    flags = 0
    kwargs = {'alias': 'energy_request_Charlie'}
    methodname = 'safe_call'
    msg = <Pyro4.message.Message at 7f447e841c88; type=5 flags=1 seq=2 datasize=2844011 #ann=0>
    objectId = 'obj_5ec94495203e477d81facdd17cd8f9dd'
    self = <osbrain.proxy.Proxy at 0x7f446d714048; connected IPv4; for PYRONAME:Charlie@127.0.0.1:10000>
        self._next_oneway = False
        self._pyroAttrs = set()
        self._pyroSerializer = None
        self._Proxy__pyroTimeout = 0.0
        self._pyroHandshake = 'hello'
        self._pyroMethods = {'run', 'raise_exception', 'bind', 'on_init', 'addr', 'log_warning', 'send_recv', 'each
', 'set_method', 'log_debug', 'set_attr', 'subscribe', 'log_error', 'close', 'kill', 'execute_as_method', 'ping', '
has_socket', 'close_all', 'idle', 'safe_call', 'connect', 'unsubscribe', 'execute_as_function', 'is_running', 'log_
info', 'shutdown', 'stop', 'list_timers', 'send', 'after', 'recv', 'stop_all_timers', 'set_logger', 'before_loop', 
'stop_timer', 'get_attr'}
        self._Proxy__async = False
        self._pyroRawWireResponse = False
        self._pyroMaxRetries = 0
        self._Proxy__pyroHmacKey = None
        self._pyroSeq = 2
        self._default_safe = True
        self._pyroOneway = {'run'}
        self._pyroUri = <Pyro4.core.URI at 0x7f446d6cf5c0; PYRONAME:Charlie@127.0.0.1:10000>
        self._safe = True
        self._pyroConnection = <Pyro4.socketutil.SocketConnection object at 0x7f446d6cfa90>
        self._Proxy__pyroConnLock = <unlocked _thread.RLock object owner=0 count=0 at 0x7f44a144a9c0>
    serializer = <Pyro4.util.CloudpickleSerializer object at 0x7f4486ed2d30>
    vargs = ['addr']

Traceback (most recent call last):
  File "main.py", line 188, in invoke_agent_ec_handle
    next_state, usable_generated_energy = l_rl_agent.do_action(l_curr_state, action, osbrain_ns, agent, args.agentn
ame, allies)
  File "/home/amitprasad53121/marl/marlagent/rlagent.py", line 141, in do_action
    energy_grant = agent_actions.request_ally(ns=ns, agent=agent, agent_name = agent_name, allies=allies, energy_am
t = abs(diff), time = time_str)
  File "/home/amitprasad53121/marl/marlagent/agent_actions.py", line 43, in request_ally
    ally_proxy_addr = ally_proxy.addr(alias=str('energy_request_'+ally_name))
  File "/usr/local/lib/python3.5/dist-packages/Pyro4/core.py", line 185, in __call__
    return self.__send(self.__name, args, kwargs)
  File "/usr/local/lib/python3.5/dist-packages/osbrain/proxy.py", line 219, in _pyroInvoke
    methodname, args, kwargs, flags, objectId)
  File "/usr/local/lib/python3.5/dist-packages/osbrain/proxy.py", line 262, in _remote_call
    flags=flags, objectId=objectId)
  File "/usr/local/lib/python3.5/dist-packages/Pyro4/core.py", line 476, in _pyroInvoke
    raise data  # if you see this in your traceback, you should probably inspect the remote traceback as well
zmq.error.ZMQError: Too many open files
Peque commented 6 years ago

@amitection Please, try to upgrade to osBrain version 0.6.2 and see if you still see that error. Reboot your computer to make sure all temporary files are cleaned-up.

amitection commented 6 years ago

@Peque Thanks. I upgraded to v0.6.2 and it seems to be working fine now.