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

DISH socket not working with asyncio context #1139

Open
dragos-vlad opened this issue Feb 9, 2018 · 12 comments
Open

DISH socket not working with asyncio context #1139

dragos-vlad opened this issue Feb 9, 2018 · 12 comments

Comments

@dragos-vlad
Copy link

Hi,

I'm trying to initialise a DISH socket using zmq.asyncio.Context fails with:

File "zmq/backend/cython/socket.pyx", line 492, in zmq.backend.cython.socket.Socket.get
server_1  |   File "zmq/backend/cython/socket.pyx", line 264, in zmq.backend.cython.socket._getsockopt
server_1  |   File "zmq/backend/cython/checkrc.pxd", line 25, in zmq.backend.cython.checkrc._check_rc
server_1  | zmq.error.ZMQError: Invalid argument

The code i'm using is:

ctx = zmq.asyncio.Context.instance()
ctx.socket(zmq.DISH)

Initialising the socket with zmq.Context works as intended.

System Info:

os: Debian 8
python: 3.6.3
pyzmq: 17.0.0.b4
libzmq: 4.2.3
Draft API available: True
@dragos-vlad
Copy link
Author

I'm also getting this exception when the application closes.

Exception ignored in: <bound method Socket.__del__ of <zmq.asyncio.Socket object at 0x7f3901bb4e18>>
 Traceback (most recent call last):
   File "/usr/local/lib/python3.6/site-packages/zmq/sugar/socket.py", line 66, in __del__
     self.close()
   File "/usr/local/lib/python3.6/site-packages/zmq/_future.py", line 157, in close
     self._clear_io_state()
   File "/usr/local/lib/python3.6/site-packages/zmq/asyncio/__init__.py", line 60, in _clear_io_state
     self.io_loop.remove_reader(self._fd)
   File "/usr/local/lib/python3.6/asyncio/selector_events.py", line 342, in remove_reader
     return self._remove_reader(fd)
   File "/usr/local/lib/python3.6/asyncio/selector_events.py", line 279, in _remove_reader
     key = self._selector.get_key(fd)
   File "/usr/local/lib/python3.6/selectors.py", line 189, in get_key
     return mapping[fileobj]
   File "/usr/local/lib/python3.6/selectors.py", line 70, in __getitem__
     fd = self._selector._fileobj_lookup(fileobj)
   File "/usr/local/lib/python3.6/selectors.py", line 224, in _fileobj_lookup
     return _fileobj_to_fd(fileobj)
   File "/usr/local/lib/python3.6/selectors.py", line 39, in _fileobj_to_fd
     "{!r}".format(fileobj)) from None
 ValueError: Invalid file object: None

@minrk
Copy link
Member

minrk commented Feb 9, 2018

do DISH sockets not have zmq.FD? If so, then they cannot be used with asyncio.

@dragos-vlad
Copy link
Author

@minrk How do I find out?

@minrk
Copy link
Member

minrk commented Feb 12, 2018

Looks like it was an explicit design choice in libzmq to not support ZMQ_FD (zeromq/libzmq#2941) in new threadsafe sockets (server/client, radio/dish, scatter/gather). Until that's fixed, you won't be able to use these sockets with asyncio or tornado. I wouldn't recommend using any of the draft-api sockets in production.

@dragos-vlad
Copy link
Author

dragos-vlad commented Feb 12, 2018

Like you mentioned in the libzmq issue it's pretty important for the final version of the sockets to expose a way for event loops to work with them. Until then I recommend we keep this issue open.

Thanks for your help.

EDIT: The docs should be updated in order to reflect the current status. If you like I could update them and make a pull request.

@minrk
Copy link
Member

minrk commented Feb 12, 2018

Adding a note to draft support that libzmq draft sockets cannot be used with eventloops would be worthwhile. Thanks!

@smalls12
Copy link

smalls12 commented Jun 3, 2021

Was poking around with RADIO/DISH and asyncio, stumbled onto this issue.
I've gone through some of the genesis of the problem.
Do we know if this is still an issue in libzmq?

@minrk
Copy link
Member

minrk commented Jun 7, 2021

Yes, still an issue and no indication of progress. It's a tricky problem and someone needs to implement it in libzmq.

@alonbl
Copy link

alonbl commented Feb 15, 2024

Hi,
It would be very nice if this can be implemented or even some hints of how to implement/what to look into.
Thanks,

@minrk
Copy link
Member

minrk commented Feb 15, 2024

This is a feature request for libzmq to implement event-loop-supporting handles for sockets. Until they address that, there isn't really anything pyzmq or users can do, other than do blocking calls in background threads. If DISH sockets get ZMQ_FD support, it should work with asyncio without any changes to pyzmq. If they choose to go another way, it might require some code in pyzmq to deal with it. There is a proposal that sounds like it would work, to me, but someone has to implement it in libzmq.

@alonbl
Copy link

alonbl commented Feb 15, 2024

Thanks for explaining that @minrk,
I will try to see if there is an open issue at libzmq side and create relationship.

@alonbl
Copy link

alonbl commented Feb 15, 2024

Found: zeromq/libzmq#2941

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

4 participants