[Python-checkins] bpo-32351: Use fastpath in asyncio.sleep if delay<0 (#4908)

Andrew Svetlov webhook-mailer at python.org
Sun Dec 17 09:41:34 EST 2017


https://github.com/python/cpython/commit/5382c05021026fe623def829d121f5f6af4909fb
commit: 5382c05021026fe623def829d121f5f6af4909fb
branch: master
author: Andrew Svetlov <andrew.svetlov at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017-12-17T16:41:30+02:00
summary:

bpo-32351: Use fastpath in asyncio.sleep if delay<0 (#4908)

* Use fastpath in asyncio.sleep if delay<0

* Add NEWS entry

files:
A Misc/NEWS.d/next/Library/2017-12-17-14-23-23.bpo-32351.95fh2K.rst
M Lib/asyncio/tasks.py

diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index cdb483ae0eb..275141c65e7 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -503,7 +503,7 @@ def __sleep0():
 
 async def sleep(delay, result=None, *, loop=None):
     """Coroutine that completes after a given time (in seconds)."""
-    if delay == 0:
+    if delay <= 0:
         await __sleep0()
         return result
 
diff --git a/Misc/NEWS.d/next/Library/2017-12-17-14-23-23.bpo-32351.95fh2K.rst b/Misc/NEWS.d/next/Library/2017-12-17-14-23-23.bpo-32351.95fh2K.rst
new file mode 100644
index 00000000000..56f52d2a418
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-12-17-14-23-23.bpo-32351.95fh2K.rst
@@ -0,0 +1 @@
+Use fastpath in asyncio.sleep if delay<0 (2x boost)



More information about the Python-checkins mailing list