Esempio n. 1
0
 def enqueue(self, *args, **kwargs):
     event = self._policy.getEvent(*args, **kwargs)
     if self._policy.argumentPassingMode == eventpy.policy.argumentPassingExcludeEvent:
         args = args[1:]
     queuedEvent = QueuedEvent(event, args, kwargs)
     with lockguard.LockGuard(self._queueListLock):
         self._queueList.append(queuedEvent)
     if self._doCanProcess():
         with lockguard.LockGuard(self._queueListMutex):
             self._queueListConditionVariable.notify()
Esempio n. 2
0
 def forEach(self, func):
     with lockguard.LockGuard(self._lock):
         node = self._list.getHead()
     counter = self._currentCounter
     invoke = _selectForEachInvoke(func)
     while node is not None:
         nodeCounter = node.getData()._counter
         if nodeCounter != 0 and counter >= nodeCounter:
             invoke(node)
         with lockguard.LockGuard(self._lock):
             node = node._next
Esempio n. 3
0
 def __call__(self, *args, **kwargs):
     with lockguard.LockGuard(self._lock):
         node = self._list.getHead()
     counter = self._currentCounter
     while node is not None:
         nodeCounter = node.getData()._counter
         if nodeCounter != 0 and counter >= nodeCounter:
             node.getData()._callback(*args, **kwargs)
             if not self._policy.canContinueInvoking(*args, **kwargs):
                 break
         with lockguard.LockGuard(self._lock):
             node = node._next
Esempio n. 4
0
 def takeEvent(self):
     if self._queueList:
         with lockguard.LockGuard(self._queueListLock):
             if self._queueList:
                 queuedEvent = self._queueList[0]
                 self._queueList = self._queueList[1:]
                 return queuedEvent
     return None
Esempio n. 5
0
 def waitFor(self, seconds):
     with lockguard.LockGuard(self._queueListMutex):
         startSeconds = time.time()
         while True:
             self._queueListConditionVariable.wait(0.001)
             if self._doCanProcess():
                 return True
             if time.time() - startSeconds >= seconds:
                 return False
Esempio n. 6
0
 def process(self):
     if self._queueList:
         with lockguard.LockGuard(self._queueListLock):
             tempList = self._queueList
             self._queueList = []
         if tempList:
             for queuedEvent in tempList:
                 self.directDispatch(queuedEvent.event, *queuedEvent.args,
                                     **queuedEvent.kwargs)
             return True
     return False
Esempio n. 7
0
 def processOne(self):
     if self._queueList:
         queuedEvent = None
         with lockguard.LockGuard(self._queueListLock):
             if self._queueList:
                 queuedEvent = self._queueList[0]
                 self._queueList = self._queueList[1:]
         if queuedEvent is not None:
             self.directDispatch(queuedEvent.event, *queuedEvent.args,
                                 **queuedEvent.kwargs)
             return True
     return False
Esempio n. 8
0
 def processIf(self, func):
     if self._queueList:
         with lockguard.LockGuard(self._queueListLock):
             tempList = self._queueList
             self._queueList = []
         if tempList:
             for queuedEvent in tempList:
                 if func(*queuedEvent.args, **queuedEvent.kwargs):
                     self.directDispatch(queuedEvent.event,
                                         *queuedEvent.args,
                                         **queuedEvent.kwargs)
                 else:
                     self._queueList.append(queuedEvent)
             return True
     return False
Esempio n. 9
0
    def _getNextCounter(self):
        self._currentCounter += 1
        result = self._currentCounter
        if result <= 0:  # overflow, let's reset all nodes' counters.
            with lockguard.LockGuard(self._lock):
                node = self._list.getHead()
                while node is not None:
                    node.getData()._counter = 1
                    node = node.getNext()
            if self._currentCounter < 0:
                self._currentCounter = 0
            self._currentCounter += 1
            result = self._currentCounter

        return result
Esempio n. 10
0
 def clearEvents(self):
     with lockguard.LockGuard(self._queueListLock):
         self._queueList = []
Esempio n. 11
0
 def __exit__(self, type, value, traceBack):
     self._queue._queueNotifyCounter -= 1
     if self._queue._doCanNotifyQueueAvailable(
     ) and not self._queue.emptyQueue():
         with lockguard.LockGuard(self._queue._queueListMutex):
             self._queue._queueListConditionVariable.notify()
Esempio n. 12
0
 def peekEvent(self):
     if self._queueList:
         with lockguard.LockGuard(self._queueListLock):
             if self._queueList:
                 return self._queueList[0]
     return None
Esempio n. 13
0
 def wait(self):
     with lockguard.LockGuard(self._queueListMutex):
         while True:
             self._queueListConditionVariable.wait(0.001)
             if self._doCanProcess():
                 break
Esempio n. 14
0
 def _doFindCallableList(self, event):
     with lockguard.LockGuard(self._eventCallbackListMapLock):
         if event in self._eventCallbackListMap:
             return self._eventCallbackListMap[event]
     return None
Esempio n. 15
0
 def _getCallbackList(self, event):
     with lockguard.LockGuard(self._eventCallbackListMapLock):
         if event not in self._eventCallbackListMap:
             self._eventCallbackListMap[event] = callbacklist.CallbackList(
                 self._policy)
         return self._eventCallbackListMap[event]