Ticket #6217: reactor.py.diff

File reactor.py.diff, 1.6 KB (added by BrianMatthews, 3 years ago)
  • .py

    old new  
    9494        # here and GetQueuedCompletionStatus in a thread. Or I could poll with
    9595        # a reasonable interval. Guess what! Threads are hard.
    9696
    97         processed_events = 0
    9897        if timeout is None:
    9998            timeout = MAX_TIMEOUT
    10099        else:
    101100            timeout = min(MAX_TIMEOUT, int(1000*timeout))
    102         rc, bytes, key, evt = self.port.getEvent(timeout)
    103         while 1:
    104             if rc == WAIT_TIMEOUT:
    105                 break
    106             if key != KEY_WAKEUP:
    107                 assert key == KEY_NORMAL
    108                 log.callWithLogger(evt.owner, self._callEventCallback,
    109                                    rc, bytes, evt)
    110                 processed_events += 1
    111             if processed_events >= EVENTS_PER_LOOP:
    112                 break
    113             rc, bytes, key, evt = self.port.getEvent(0)
     101        # pull all the existing events
     102        events = []
     103        event = self.port.getEvent(timeout)
     104        while event[0] != WAIT_TIMEOUT:
     105            if event[2] == KEY_NORMAL:
     106                events.append(event)
     107            event = self.port.getEvent(0)
    114108
     109        #process them
     110        for (rc, bytes, key, evt) in events:
     111            log.callWithLogger(evt.owner, self._callEventCallback,
     112                               rc, bytes, evt)
    115113
     114
    116115    def _callEventCallback(self, rc, bytes, evt):
    117116        owner = evt.owner
    118117        why = None