Example #1
0
 def unblock_event(self, event):
     if event in self.event_handlers:
         if self.event_handlers[event].blocker_tokens:
             log.debug2("Unblocking an event: %s", event)
             self.event_handlers[event].blocker_tokens.pop()
         else:
             log.debug("Trying to unblock non-blocked event '%s'", event)
     else:
         log.info("Trying to unblock an unknown event: %s", event)
Example #2
0
 def block_event(self, event, disable_log=False):
     if event in self.event_handlers:
         self.event_handlers[event].blocker_tokens.append(True)
         if not disable_log:
             log.debug2("Blocking an event: %s (%d blockers reached)",
                        event,
                        len(self.event_handlers[event].blocker_tokens))
     else:
         if not disable_log:
             log.info("Trying to block an unknown event: %s", event)
Example #3
0
 def emit_event(self, event, *args, **kwargs):
     log.debug2("Event emitted: %s", event)
     if event in self.event_handlers:
         if self.event_handlers[event].blocker_tokens:
             log.debug2("Ignoring blocked event: %s", event)
             return
         # prevent infinite recursion
         with self.blocked_events({event}):
             for handler in self.event_handlers[event].handlers:
                 handler.func(*(handler.args + args), **kwargs)
     else:
         log.debug("No events registered for event '%s'", event)
Example #4
0
 def emit_event(self, event, *args, **kwargs):
     log.debug2("Event emitted: %s", str(event))
     if event in self.event_handlers:
         if self.event_handlers[event].blocker_tokens:
             return
         # prevent infinite recursion
         self.block_event(event)
         for handler in self.event_handlers[event].handlers:
             handler.func(*(handler.args + args), **kwargs)
         self.unblock_event(event)
     else:
         log.debug("No events registered for event '%s'", str(event))
Example #5
0
 def emit_event(self, event, *args, **kwargs):
     log.debug2("Event emitted: %s" % str(event))
     if event in self.event_handlers:
         if self.event_handlers[event][EVENT_BLOCKER_INDEX] != 0:
             return
         # prevent infinite recursion
         self.block_event(event)
         for handler in self.event_handlers[event][EVENT_HANDLER_INDEX]:
             func = handler[HANDLER_FUNC_INDEX]
             data = handler[HANDLER_ARG_INDEX]
             func(*(data + args), **kwargs)
         self.unblock_event(event)
     else:
         log.debug("No events registered for event '%s'" % str(event))
Example #6
0
 def emit_event(self, event, *args, **kwargs):
     log.debug2("Event emitted: %s" % str(event))
     if event in self.event_handlers:
         if self.event_handlers[event][EVENT_BLOCKER_INDEX] != 0:
             return
         # prevent infinite recursion
         self.block_event(event)
         for handler in self.event_handlers[event][EVENT_HANDLER_INDEX]:
             func = handler[HANDLER_FUNC_INDEX]
             data = handler[HANDLER_ARG_INDEX]
             func(*(data + args), **kwargs)
         self.unblock_event(event)
     else:
         log.debug("No events registered for event '%s'" % str(event))
Example #7
0
 def unblock_event(self, event, disable_log=False):
     if event in self.event_handlers:
         if self.event_handlers[event].blocker_tokens:
             self.event_handlers[event].blocker_tokens.pop()
             if not disable_log:
                 log.debug2(
                     "Unblocking an event: %s (%d blockers remaining)",
                     event, len(self.event_handlers[event].blocker_tokens))
         else:
             if not disable_log:
                 log.debug("Trying to unblock non-blocked event '%s'",
                           event)
     else:
         # "disable_log" is only relevant for the debugging messages above
         log.info("Trying to unblock an unknown event: %s", event)
Example #8
0
 def emit_event(self, event):
     log.debug2("Event emitted: %s", event)
     if event in self.event_handlers:
         self.event_handlers[event].statistics["emitted"] += 1
         if self.event_handlers[event].blocker_tokens:
             self.event_handlers[event].statistics["blocked"] += 1
             log.debug2("Ignoring blocked event: %s", event)
         else:
             # prevent infinite recursion
             with self.blocked_events({event}, disable_log=True):
                 self.event_handlers[event].statistics["handled"] += 1
                 for handler in self.event_handlers[event].handlers:
                     log.debug2("Calling event handler: %s", handler)
                     if isinstance(handler, str):
                         # event names are acceptable
                         self.emit_event(handler)
                     else:
                         handler()
     else:
         log.debug("No events registered for event '%s'", event)
Example #9
0
 def block_event(self, event):
     if event in self.event_handlers:
         log.debug2("Blocking an event: %s", event)
         self.event_handlers[event].blocker_tokens.append(True)
     else:
         log.info("Trying to block an unknown event: %s", event)