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
zmq.asyncio.Context.instance() returns synchronous version of zmq.Context object #1172
Comments
The asyncio context inherits from zmq.Context and only overrides the Socket class. In zmq.asyncio class Context(_zmq.Context):
"""Context for creating asyncio-compatible Sockets"""
_socket_class = Socket It does not override the instance() method, hence why you see the sugar context object as the method is called on the parent class. It however is the asyncio Context as the socket class is the asyncio one. A simple test will show. If I change the asyncio Context class as below: class Context(_zmq.Context):
"""Context for creating asyncio-compatible Sockets"""
_socket_class = Socket
@classmethod
def instance(cls, io_threads=1):
return super(Context, self).instance(cls, io_threads) I am overriding the method and manually calling the parent whereas python would do that automatically. Your example now displays correctly. import zmq
import zmq.asyncio
zmq.asyncio.Context.instance()
<zmq.asyncio.Context object at 0x7f2524501f98>
zmq.Context.instance()
<zmq.sugar.context.Context object at 0x7f25242c5198> I think there is an issue with repr() of a class when it is created with a @classmethod method and inheritance. We could fix the repr() with my update above, but that feels wrong. |
This behavior is problematic, as socket objects returned by zmq.asyncio.Context.instance().socket() are zmq.Socket type not zmq.asyncio.Socket (with pyzmq version 17.1.2):
|
There are also some occasions that an |
The problem is that the two classes share the same singleton instance, which is located in In my particular use case, the two
|
I believe it should return an async-compatible (
zmq.asyncio.Context
) global object instead ofzmq.sugar.context.Context
global object.If this is an intended behavior, it must be explicitly documented here.
The text was updated successfully, but these errors were encountered: