コード例 #1
0
 def __init__(self):
     """
     Creates new EventReactor with standard SynchronizedQueue and __QueueOperator
     """
     self.__event_queue = SynchronizedQueue()
     self.__enqueuer = __QueueOperator(self.__event_queue)
     
     self.__rshift__ = self.__enqueuer.__rshift__
     self.__lshift__ = self.__enqueuer.__lshift__
     
     self.__last_access_time = sys.current_time()
コード例 #2
0
 def poll(self):
     """
     When called, one pending event will be resolved.
     Returns True if at least one event was resolved or False if queue is empty
     """
     dif = sys.current_time() - self.__last_access_time
     self.__last_access_time = sys.current_time() 
     with self.__event_queue.mutex:
         if self.__event_queue.has_elements():
             event = self.__event_queue.poll()
             event.currentPTime -= dif
             if event.currentPTime <= 0:
                 event.currentPTime = event.periodTime
                 self.fire_event(event)
                 if event.periodic:
                     self.__enqueuer.enqueue(event)
                 return True
             else:
                 self.__event_queue.add(event)
         return False