Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2f440b

Browse files
committed
Merge pull request 0rpc#59 from lopter/master
"Less ugly" pyzmq 13.0.0 fix for context.py and better comments about the issue
2 parents 90f7c8e + 02ef63e commit c2f440b

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

zerorpc/context.py

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@
3232
class Context(zmq.Context):
3333
_instance = None
3434

35-
# Since pyzmq 13.0.0 implicit assignation is forbidden. Thankfully we are
36-
# allowed to define our attributes here, and initialize them per instance
37-
# later.
38-
_middlewares = None
39-
_hooks = None
40-
_msg_id_base = None
41-
_msg_id_counter = None
42-
_msg_id_counter_stop = None
43-
4435
def __init__(self):
4536
super(zmq.Context, self).__init__()
4637
self._middlewares = []
@@ -57,6 +48,50 @@ def __init__(self):
5748
}
5849
self._reset_msgid()
5950

51+
# NOTE: pyzmq 13.0.0 messed up with setattr (they turned it into a
52+
# non-op) and you can't assign attributes normally anymore, hence the
53+
# tricks with self.__dict__ here
54+
55+
@property
56+
def _middlewares(self):
57+
return self.__dict__['_middlewares']
58+
59+
@_middlewares.setter
60+
def _middlewares(self, value):
61+
self.__dict__['_middlewares'] = value
62+
63+
@property
64+
def _hooks(self):
65+
return self.__dict__['_hooks']
66+
67+
@_hooks.setter
68+
def _hooks(self, value):
69+
self.__dict__['_hooks'] = value
70+
71+
@property
72+
def _msg_id_base(self):
73+
return self.__dict__['_msg_id_base']
74+
75+
@_msg_id_base.setter
76+
def _msg_id_base(self, value):
77+
self.__dict__['_msg_id_base'] = value
78+
79+
@property
80+
def _msg_id_counter(self):
81+
return self.__dict__['_msg_id_counter']
82+
83+
@_msg_id_counter.setter
84+
def _msg_id_counter(self, value):
85+
self.__dict__['_msg_id_counter'] = value
86+
87+
@property
88+
def _msg_id_counter_stop(self):
89+
return self.__dict__['_msg_id_counter_stop']
90+
91+
@_msg_id_counter_stop.setter
92+
def _msg_id_counter_stop(self, value):
93+
self.__dict__['_msg_id_counter_stop'] = value
94+
6095
@staticmethod
6196
def get_instance():
6297
if Context._instance is None:

zerorpc/gevent_zmq.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ class Socket(_zmq.Socket):
4747
def __init__(self, context, socket_type):
4848
super(Socket, self).__init__(context, socket_type)
4949
on_state_changed_fd = self.getsockopt(_zmq.FD)
50-
# Since pyzmq 13.0.0 implicit assignation is forbidden. Trying to define
51-
# the attributes as a class member first do not work either because the
52-
# setattr is a non-op! So we are doing it the ugly way.
50+
# NOTE: pyzmq 13.0.0 messed up with setattr (they turned it into a
51+
# non-op) and you can't assign attributes normally anymore, hence the
52+
# tricks with self.__dict__ here
5353
self.__dict__["_readable"] = gevent.event.Event()
5454
self.__dict__["_writable"] = gevent.event.Event()
5555
try:

0 commit comments

Comments
 (0)