]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Timeout micro-optimizations.
authorBen Darnell <ben@bendarnell.com>
Sun, 20 Apr 2014 00:13:40 +0000 (20:13 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 20 Apr 2014 00:13:40 +0000 (20:13 -0400)
Use the (C) timedelta.total_seconds function when available.  But it's
still a bit faster to use numeric timeouts instead of back-and-forth
through timedelta, so do that instead in http1connection.

tornado/http1connection.py
tornado/ioloop.py

index 5c50fad000df0512ff49431a28909c575d0941fc..787003c86cb4ec6cdfb068f180a411842bb9b8ee 100644 (file)
@@ -124,7 +124,7 @@ class HTTP1Connection(object):
             else:
                 try:
                     header_data = yield gen.with_timeout(
-                        datetime.timedelta(seconds=self._header_timeout),
+                        self.stream.io_loop.time() + self._header_timeout,
                         header_future,
                         io_loop=self.stream.io_loop)
                 except gen.TimeoutError:
index 77fb46591a521fc864bf740436ba9e9e1a37305e..208db885342b3c19792c5abab0e1cb5893b6554d 100644 (file)
@@ -831,7 +831,11 @@ class _Timeout(object):
         if isinstance(deadline, numbers.Real):
             self.deadline = deadline
         elif isinstance(deadline, datetime.timedelta):
-            self.deadline = io_loop.time() + _Timeout.timedelta_to_seconds(deadline)
+            now = io_loop.time()
+            try:
+                self.deadline = now + deadline.total_seconds()
+            except AttributeError:  # py2.6
+                self.deadline = now + _Timeout.timedelta_to_seconds(deadline)
         else:
             raise TypeError("Unsupported deadline %r" % deadline)
         self.callback = callback