reactor: Reload eventtime if a greenlet is reactivated

Fix a bug causing timers to be delayed when pause() is called from a
fd event.  The eventtime needs to be reloaded when an old greenlet is
reactivated.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-01-10 10:55:46 -05:00
parent 93d3a6e1d1
commit 46b6b4037d
1 changed files with 5 additions and 2 deletions

View File

@ -106,6 +106,7 @@ class SelectReactor:
fd.callback(eventtime) fd.callback(eventtime)
if g_dispatch is not self._g_dispatch: if g_dispatch is not self._g_dispatch:
self._end_greenlet(g_dispatch) self._end_greenlet(g_dispatch)
eventtime = time.time()
break break
self._g_dispatch = None self._g_dispatch = None
def run(self): def run(self):
@ -138,13 +139,14 @@ class PollReactor(SelectReactor):
self._g_dispatch = g_dispatch = greenlet.getcurrent() self._g_dispatch = g_dispatch = greenlet.getcurrent()
eventtime = time.time() eventtime = time.time()
while self._process: while self._process:
timeout = int(math.ceil(self._check_timers(eventtime) * 1000.)) timeout = self._check_timers(eventtime)
res = self._poll.poll(timeout) res = self._poll.poll(int(math.ceil(timeout * 1000.)))
eventtime = time.time() eventtime = time.time()
for fd, event in res: for fd, event in res:
self._fds[fd](eventtime) self._fds[fd](eventtime)
if g_dispatch is not self._g_dispatch: if g_dispatch is not self._g_dispatch:
self._end_greenlet(g_dispatch) self._end_greenlet(g_dispatch)
eventtime = time.time()
break break
self._g_dispatch = None self._g_dispatch = None
@ -179,6 +181,7 @@ class EPollReactor(SelectReactor):
self._fds[fd](eventtime) self._fds[fd](eventtime)
if g_dispatch is not self._g_dispatch: if g_dispatch is not self._g_dispatch:
self._end_greenlet(g_dispatch) self._end_greenlet(g_dispatch)
eventtime = time.time()
break break
self._g_dispatch = None self._g_dispatch = None