summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-11-05 19:30:41 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-11-05 19:30:41 (GMT)
commita2149ed1c0d1b76a6cba0a2c452163360cc0106a (patch)
tree2aa24d47097fbf1cfa8cf00a459a6adcbe06286c /Lib
parent7c1455be6be4f698889527e6e46086f229a73818 (diff)
parent7931be403d6f616777e4a46cf43ee0bd21374889 (diff)
downloadcpython-a2149ed1c0d1b76a6cba0a2c452163360cc0106a.zip
cpython-a2149ed1c0d1b76a6cba0a2c452163360cc0106a.tar.gz
cpython-a2149ed1c0d1b76a6cba0a2c452163360cc0106a.tar.bz2
Merge 3.5
Diffstat (limited to 'Lib')
-rw-r--r--Lib/asyncio/tasks.py4
-rw-r--r--Lib/test/test_asyncio/test_tasks.py24
2 files changed, 28 insertions, 0 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index b887d88..77a93e0 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -488,6 +488,10 @@ def as_completed(fs, *, loop=None, timeout=None):
@coroutine
def sleep(delay, result=None, *, loop=None):
"""Coroutine that completes after a given time (in seconds)."""
+ if delay == 0:
+ yield
+ return result
+
future = futures.Future(loop=loop)
h = future._loop.call_later(delay,
future._set_result_unless_cancelled, result)
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index 9772bae..b492cf0 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -2188,5 +2188,29 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
self.assertEqual(context['exception'], exc_context.exception)
+class SleepTests(test_utils.TestCase):
+ def setUp(self):
+ self.loop = asyncio.new_event_loop()
+ asyncio.set_event_loop(None)
+
+ def test_sleep_zero(self):
+ result = 0
+
+ def inc_result(num):
+ nonlocal result
+ result += num
+
+ @asyncio.coroutine
+ def coro():
+ self.loop.call_soon(inc_result, 1)
+ self.assertEqual(result, 0)
+ num = yield from asyncio.sleep(0, loop=self.loop, result=10)
+ self.assertEqual(result, 1) # inc'ed by call_soon
+ inc_result(num) # num should be 11
+
+ self.loop.run_until_complete(coro())
+ self.assertEqual(result, 11)
+
+
if __name__ == '__main__':
unittest.main()