MCPcopy
hub / github.com/saltstack/salt / SaltEvent

Class SaltEvent

salt/utils/event.py:232–1057  ·  view source on GitHub ↗

Warning! Use the get_event function or the code will not be RAET compatible The base class used to manage salt events

Source from the content-addressed store, hash-verified

230
231
232class SaltEvent:
233 """
234 Warning! Use the get_event function or the code will not be
235 RAET compatible
236 The base class used to manage salt events
237 """
238
239 # Live SaltEvent instances tracked weakly so the at-fork handler can
240 # drop ZMQ pub/push sockets and asyncio/tornado loops inherited by
241 # any forked child. Sharing a parent's subscriber across sibling
242 # children races the SUB-side message dispatch and deadlocks the
243 # asyncio loop the same way RemoteClient does -- see fileclient.py.
244 _instances = weakref.WeakSet()
245 _atfork_registered = False
246
247 @classmethod
248 def _register_atfork(cls):
249 if cls._atfork_registered or not hasattr(os, "register_at_fork"):
250 return
251 os.register_at_fork(after_in_child=cls._after_fork_in_child)
252 cls._atfork_registered = True
253
254 @classmethod
255 def _after_fork_in_child(cls):
256 # Drop inherited ZMQ socket / IOLoop references without close():
257 # close() would tear down FDs and asyncio loop state copied from
258 # the parent and could affect the parent's bus. Connections will
259 # be lazily reopened by connect_pub() / connect_pull() on next
260 # use.
261 for inst in list(cls._instances):
262 try:
263 inst.subscriber = None
264 inst.pusher = None
265 inst.cpub = False
266 inst.cpush = False
267 except Exception: # pylint: disable=broad-except
268 pass
269
270 def __enter__(self):
271 return self
272
273 def __exit__(self, exc_type, exc_val, exc_tb):
274 self.destroy()
275
276 def __init__(
277 self,
278 node,
279 sock_dir=None,
280 opts=None,
281 listen=True,
282 io_loop=None,
283 keep_loop=False,
284 raise_errors=False,
285 ):
286 """
287 :param IOLoop io_loop: Pass in an io_loop if you want asynchronous
288 operation for obtaining events. Eg use of
289 set_event_handler() API. Otherwise, operation

Calls

no outgoing calls