Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically created Loops should be closed automatically #14

Open
kmaehashi opened this issue Aug 15, 2016 · 2 comments
Open

Automatically created Loops should be closed automatically #14

kmaehashi opened this issue Aug 15, 2016 · 2 comments

Comments

@kmaehashi
Copy link

Constructor of msgpackrpc.Session class has an optional argument loop=None. When loop is not specified, new Loop will be automatically created in the constructor.

However, as automatically-created Loops are not closed automatically, it uses more file descriptors than expected. This becomes an issue for clients that connects/disconnects frequently.
I think automatically-created Loops should be closed (i.e., session._loop._ioloop.close()) when its associated Session is closed.

I have two ideas:

  1. If Loop instance is not specified by user (i.e., automatically created in Session constructor), close the Loop when session.close() method is called.
  2. Add close_loop=True to the Session constructor argument. Close the Loop only if close_loop is set to True when session.close() method is called. This behavior is similar to closefd option of io.FileIO.

In addition, it is better to add close() method to msgpackrpc.Loop class, to allow users to close the internal tornado IOLoop.

@wosiu
Copy link

wosiu commented Sep 9, 2018

+1
I use rpc client in my django server (to call c++ rpc server) and after a while I get:
[Errno 24] Too many open files

@kmaehashi
Copy link
Author

Current workaround:

cli = msgpackrpc.Client(...)
try:
  cli.call(...)
finally:
  cli.close()
  cli._loop._ioloop.close()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants