Пример #1
0
  def poll(self, limit=0):
    """ Listen on the pipe for any pending events and then return 
    
        This is not a blocking operation, at most 'limit' events will
        be processed (prevent recursive spam).

        Returns False if the pipe is dead.
    """
    count = 0
    while limit == 0 or count < limit:
      if self._pipe.poll():
        try:
          data = self._pipe.recv()
        except Exception:
          e = exception()
          log.info("Messenger: Remote process terminated")
          return False
        processed = 0
        for _, v in self._listeners.items():
          for i in v:
            if i.matches(data):
                try:
                  i.invoke(data)
                except Exception:
                  e = exception()
                  log.error("Failed to invoked bound trigger: %s" % e)
                processed += 1
        if processed == 0:
          log.warn("Warning! Failed to dispatch unbound event id: %d" % data.id)
      else:
        break
      if limit > 0:
        count += 1
    return True
Пример #2
0
 def trigger(self, uid, event=None):
   """ Trigger an event on the remote messenger 
   
       Actually all this function does is wrap the id and event and pass
       it to the pipe. The remote side must handle the event to dispatch it
       
       If the pipe is closed, trigger does nothing. It's up to the user
       to make sure the client thread terminates nicely.
   """
   item = Event(uid, event)
   try:
     self._pipe.send(item)
   except Exception:
     e = exception()
     log.error("Failed to trigger event: %d: %s" % (uid, e))