@@ -52,9 +52,14 @@ def __del__(self) -> None:
52
52
53
53
54
54
@classmethod
55
- def get_socket (cls , * , id : str , node_type : str , context : zmq .asyncio .Context | zmq .Context ,
56
- transport : ZMQ_TRANSPORTS = ZMQ_TRANSPORTS .IPC , socket_type : zmq .SocketType = zmq .ROUTER ,
57
- ** kwargs ) -> typing .Tuple [zmq .Socket , str ]:
55
+ def get_socket (cls , * ,
56
+ id : str ,
57
+ node_type : str ,
58
+ context : zmq .asyncio .Context | zmq .Context ,
59
+ transport : ZMQ_TRANSPORTS = ZMQ_TRANSPORTS .IPC ,
60
+ socket_type : zmq .SocketType = zmq .ROUTER ,
61
+ ** kwargs
62
+ ) -> typing .Tuple [zmq .Socket , str ]:
58
63
"""
59
64
Create a socket with certain specifications. Supported ZeroMQ transports are TCP, IPC & INPROC.
60
65
For IPC sockets, a file is created under TEMP_DIR of global configuration.
@@ -164,7 +169,7 @@ def create_socket(self, *, id: str, node_type: str = 'server', context: zmq.asyn
164
169
"""
165
170
if context and not isinstance (context , zmq .asyncio .Context ):
166
171
raise TypeError ("async ZMQ message broker accepts only async ZMQ context. supplied type {}" .format (type (context )))
167
- self .context = context or global_config .zmq_context (asynch = True )
172
+ self .context = context or global_config .zmq_context ()
168
173
self .socket , self .socket_address = BaseZMQ .get_socket (id = id , node_type = node_type , context = self .context ,
169
174
transport = transport , socket_type = socket_type , ** kwargs )
170
175
self .logger .info ("created socket {} with address {} & identity {} and {}" .format (get_socket_type_name (socket_type ),
@@ -183,17 +188,9 @@ def create_socket(self, *, id: str, node_type: str = 'server', context: zmq.Cont
183
188
Overloads ``create_socket()`` to create, bind/connect a synchronous socket. A synchronous context is created
184
189
if none is supplied.
185
190
"""
186
- socket_class = None
187
- if context :
188
- if not isinstance (context , zmq .Context ):
189
- raise TypeError ("sync ZMQ message broker accepts only sync ZMQ context. supplied type {}" .format (type (context )))
190
- if isinstance (context , zmq .asyncio .Context ):
191
- # create sync socket when async context is supplied for sync brokers.
192
- # especially useful for INPROC sync client where teh context needs to be shared and the server is async.
193
- socket_class = zmq .Socket
194
- self .context = context or global_config .zmq_context (asynch = False )
191
+ self .context = context or global_config .zmq_context ()
195
192
self .socket , self .socket_address = BaseZMQ .get_socket (id = id , node_type = node_type , context = self .context ,
196
- transport = transport , socket_type = socket_type , socket_class = socket_class ,
193
+ transport = transport , socket_type = socket_type , socket_class = zmq . Socket ,
197
194
** kwargs )
198
195
self .logger .info ("created socket {} with address {} & identity {} and {}" .format (get_socket_type_name (socket_type ),
199
196
self .socket_address , id , "bound" if node_type == 'server' else "connected" ))
@@ -593,7 +590,7 @@ class ZMQServerPool(BaseZMQServer):
593
590
"""
594
591
595
592
def __init__ (self , * , ids : typing .List [str ] | None = None , ** kwargs ) -> None :
596
- self .context = global_config .zmq_context (asynch = True )
593
+ self .context = global_config .zmq_context ()
597
594
self .poller = zmq .asyncio .Poller ()
598
595
self .pool = dict () # type: typing.Dict[str, AsyncZMQServer]
599
596
if ids :
@@ -791,8 +788,13 @@ def exit(self) -> None:
791
788
self .poller .unregister (self ._monitor_socket )
792
789
# print("poller exception did not occur 3")
793
790
except Exception as ex :
794
- self .logger .warning (f"unable to deregister from poller - { str (ex )} " )
795
-
791
+ # raises a weird key error for some reason
792
+ # unable to deregister from poller - <zmq.asyncio.Socket(zmq.PAIR) at 0x1c9e5028830> - KeyError
793
+ # unable to deregister from poller - <zmq.asyncio.Socket(zmq.PAIR) at 0x1c9e502a350> - KeyError
794
+ # unable to deregister from poller - <zmq.asyncio.Socket(zmq.PAIR) at 0x1c9e5080750> - KeyError
795
+ # unable to deregister from poller - <zmq.asyncio.Socket(zmq.PAIR) at 0x1c9e5082430> - KeyError
796
+ # self.logger.warning(f"unable to deregister from poller - {str(ex)} - {type(ex).__name__}")
797
+ pass
796
798
try :
797
799
if self ._monitor_socket is not None :
798
800
self ._monitor_socket .close (0 )
@@ -1341,7 +1343,7 @@ def __init__(self,
1341
1343
if len (client_ids ) != len (server_ids ):
1342
1344
raise ValueError ("client_ids and server_ids must have same length" )
1343
1345
# this class does not call create_socket method
1344
- self .context = context or global_config .zmq_context (asynch = True )
1346
+ self .context = context or global_config .zmq_context ()
1345
1347
self .pool = dict () # type: typing.Dict[str, AsyncZMQClient]
1346
1348
self .poller = zmq .asyncio .Poller ()
1347
1349
for client_id , server_id in zip (client_ids , server_ids ):
@@ -1941,11 +1943,13 @@ def __init__(self,
1941
1943
** kwargs
1942
1944
) -> None :
1943
1945
if isinstance (self , BaseSyncZMQ ):
1944
- self .context = context or global_config .zmq_context (asynch = False )
1946
+ self .context = context or global_config .zmq_context ()
1945
1947
self .poller = zmq .Poller ()
1948
+ socket_class = zmq .Socket
1946
1949
elif isinstance (self , BaseAsyncZMQ ):
1947
- self .context = context or global_config .zmq_context (asynch = True )
1950
+ self .context = context or global_config .zmq_context ()
1948
1951
self .poller = zmq .asyncio .Poller ()
1952
+ socket_class = zmq .asyncio .Socket
1949
1953
else :
1950
1954
raise TypeError ("BaseEventConsumer must be subclassed by either BaseSyncZMQ or BaseAsyncZMQ" )
1951
1955
super ().__init__ (id = id , server_id = kwargs .get ('server_id' , None ), ** kwargs )
@@ -1960,13 +1964,13 @@ def __init__(self,
1960
1964
)
1961
1965
self .event_unique_identifier = bytes (event_unique_identifier , encoding = 'utf-8' )
1962
1966
short_uuid = uuid4 ().hex [:8 ]
1963
- self .interruptor = self .context .socket (zmq .PAIR )
1967
+ self .interruptor = self .context .socket (zmq .PAIR , socket_class = socket_class )
1964
1968
self .interruptor .setsockopt_string (zmq .IDENTITY , f'interrupting-server-{ short_uuid } ' )
1965
- self .interrupting_peer = self .context .socket (zmq .PAIR )
1969
+ self .interrupting_peer = self .context .socket (zmq .PAIR , socket_class = socket_class )
1966
1970
self .interrupting_peer .setsockopt_string (zmq .IDENTITY , f'interrupting-client-{ short_uuid } ' )
1967
1971
self .interruptor .bind (f'inproc://{ self .id } -{ short_uuid } /interruption' )
1968
1972
self .interrupting_peer .connect (f'inproc://{ self .id } -{ short_uuid } /interruption' )
1969
-
1973
+
1970
1974
1971
1975
def subscribe (self ) -> None :
1972
1976
self .socket .setsockopt (zmq .SUBSCRIBE , self .event_unique_identifier )
@@ -1993,8 +1997,10 @@ def exit(self):
1993
1997
self .poller .unregister (self .socket )
1994
1998
self .poller .unregister (self .interruptor )
1995
1999
except Exception as E :
1996
- self .logger .warning ("could not properly terminate socket or attempted to terminate an already terminated socket of event consuming socket at address '{}'. Exception message: {}" .format (
1997
- self .socket_address , str (E )))
2000
+ # self.logger.warning("could not properly terminate socket or attempted to terminate an already terminated socket of event consuming socket at address '{}'. Exception message: {}".format(
2001
+ # self.socket_address, str(E)))
2002
+ # above line prints too many warnings
2003
+ pass
1998
2004
try :
1999
2005
self .socket .close (0 )
2000
2006
self .interruptor .close (0 )
0 commit comments