MCPcopy
hub / github.com/zeromq/pyzmq / get_monitor_socket

Method get_monitor_socket

zmq/sugar/socket.py:1066–1111  ·  view source on GitHub ↗

Return a connected PAIR socket ready to receive the event notifications. .. versionadded:: libzmq-4.0 .. versionadded:: 14.0 Parameters ---------- events : int default: `zmq.EVENT_ALL` The bitmask defining which events are wanted.

(
        self: _SocketType, events: int | None = None, addr: str | None = None
    )

Source from the content-addressed store, hash-verified

1064 return evts.get(self, 0)
1065
1066 def get_monitor_socket(
1067 self: _SocketType, events: int | None = None, addr: str | None = None
1068 ) -> _SocketType:
1069 """Return a connected PAIR socket ready to receive the event notifications.
1070
1071 .. versionadded:: libzmq-4.0
1072 .. versionadded:: 14.0
1073
1074 Parameters
1075 ----------
1076 events : int
1077 default: `zmq.EVENT_ALL`
1078 The bitmask defining which events are wanted.
1079 addr : str
1080 The optional endpoint for the monitoring sockets.
1081
1082 Returns
1083 -------
1084 socket : zmq.Socket
1085 The PAIR socket, connected and ready to receive messages.
1086 """
1087 # safe-guard, method only available on libzmq >= 4
1088 if zmq.zmq_version_info() < (4,):
1089 raise NotImplementedError(
1090 f"get_monitor_socket requires libzmq >= 4, have {zmq.zmq_version()}"
1091 )
1092
1093 # if already monitoring, return existing socket
1094 if self._monitor_socket:
1095 if self._monitor_socket.closed:
1096 self._monitor_socket = None
1097 else:
1098 return self._monitor_socket
1099
1100 if addr is None:
1101 # create endpoint name from internal fd
1102 addr = f"inproc://monitor.s-{self.FD}"
1103 if events is None:
1104 # use all events
1105 events = zmq.EVENT_ALL
1106 # attach monitoring socket
1107 self.monitor(addr, events)
1108 # create new PAIR socket and connect it
1109 self._monitor_socket = self.context.socket(zmq.PAIR)
1110 self._monitor_socket.connect(addr)
1111 return self._monitor_socket
1112
1113 def disable_monitor(self) -> None:
1114 """Shutdown the PAIR socket (created using get_monitor_socket)

Callers 5

test_monitor_repeatFunction · 0.80
test_monitor_connectedFunction · 0.80
simple_monitor.pyFile · 0.80
event_monitorFunction · 0.80
event_monitor_asyncFunction · 0.80

Calls 3

monitorMethod · 0.95
socketMethod · 0.45
connectMethod · 0.45

Tested by 2

test_monitor_repeatFunction · 0.64
test_monitor_connectedFunction · 0.64