]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Do what it says on the tin
authorAntoine Pitrou <antoine@python.org>
Thu, 3 Nov 2016 10:23:39 +0000 (11:23 +0100)
committerAntoine Pitrou <antoine@python.org>
Thu, 3 Nov 2016 10:23:39 +0000 (11:23 +0100)
tornado/ioloop.py

index c69da9e95fb8bcb6febf8657d10ed67e75b70035..006b0b4d75b989f510c2aaf6ebfe8fb79bfe7ee7 100644 (file)
@@ -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: