Format: text/x-python
⬇ Download File (843 B)
   1  """A PUB log handler."""
   2  import warnings
   3  
   4  from zmq.log.handlers import PUBHandler
   5  
   6  warnings.warn(
   7      "ipykernel.log is deprecated. It has moved to ipyparallel.engine.log",
   8      DeprecationWarning,
   9      stacklevel=2,
  10  )
  11  
  12  
  13  class EnginePUBHandler(PUBHandler):
  14      """A simple PUBHandler subclass that sets root_topic"""
  15  
  16      engine = None
  17  
  18      def __init__(self, engine, *args, **kwargs):
  19          """Initialize the handler."""
  20          PUBHandler.__init__(self, *args, **kwargs)
  21          self.engine = engine
  22  
  23      @property  # type:ignore[misc]
  24      def root_topic(self):
  25          """this is a property, in case the handler is created
  26          before the engine gets registered with an id"""
  27          if isinstance(getattr(self.engine, "id", None), int):
  28              return "engine.%i" % self.engine.id  # type:ignore[union-attr]
  29          return "engine"
  30