From: Antoine Pitrou Date: Thu, 3 Nov 2016 10:23:39 +0000 (+0100) Subject: Do what it says on the tin X-Git-Tag: v4.5.0~61^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71cfaf666a7637f44d7541015c4780817cd4ab03;p=thirdparty%2Ftornado.git Do what it says on the tin --- diff --git a/tornado/ioloop.py b/tornado/ioloop.py index c69da9e95..006b0b4d7 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -798,6 +798,10 @@ class PollIOLoop(IOLoop): try: while True: + # Prevent IO event starvation by delaying new callbacks + # to the next iteration of the event loop. + ncallbacks = len(self._callbacks) + # Add any timeouts that have come due to the callback list. # Do not run anything until we have determined which ones # are ready, so timeouts that call add_timeout cannot @@ -825,10 +829,7 @@ class PollIOLoop(IOLoop): if x.callback is not None] heapq.heapify(self._timeouts) - # Prevent IO event starvation by delaying new callbacks - # to the next iteration of the event loop. - n = len(self._callbacks) - for i in range(n): + for i in range(ncallbacks): self._run_callback(self._callbacks.popleft()) for timeout in due_timeouts: if timeout.callback is not None: