cpython: 13ff8645be57 (original) (raw)
Mercurial > cpython
changeset 90314:13ff8645be57
syncio.tasks: Fix CoroWrapper to workaround yield-from bug in CPython < 3.4.1 Closes issue #21209. [#21209]
Yury Selivanov yselivanov@sprymix.com | |
---|---|
date | Mon, 14 Apr 2014 22:24:51 -0400 |
parents | 54f1168036f1 |
children | f021049608a1 |
files | Lib/asyncio/tasks.py Lib/test/test_asyncio/test_tasks.py Misc/NEWS |
diffstat | 3 files changed, 32 insertions(+), 1 deletions(-)[+] [-] Lib/asyncio/tasks.py 5 Lib/test/test_asyncio/test_tasks.py 25 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -49,7 +49,10 @@ class CoroWrapper: def next(self): return next(self.gen)
- def send(self, *value):
# We use `*value` because of a bug in CPythons prior[](#l1.9)
# to 3.4.1. See issue #21209 and test_yield_from_corowrapper[](#l1.10)
# for details. This workaround should be removed in 3.5.0.[](#l1.11) return self.gen.send(value)[](#l1.12)
--- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -1386,6 +1386,31 @@ class TaskTests(unittest.TestCase): self.assertRaises(ValueError, self.loop.run_until_complete, asyncio.wait([], loop=self.loop))
- def test_yield_from_corowrapper(self):
old_debug = asyncio.tasks._DEBUG[](#l2.8)
asyncio.tasks._DEBUG = True[](#l2.9)
try:[](#l2.10)
@asyncio.coroutine[](#l2.11)
def t1():[](#l2.12)
return (yield from t2())[](#l2.13)
@asyncio.coroutine[](#l2.15)
def t2():[](#l2.16)
f = asyncio.Future(loop=self.loop)[](#l2.17)
asyncio.Task(t3(f), loop=self.loop)[](#l2.18)
return (yield from f)[](#l2.19)
@asyncio.coroutine[](#l2.21)
def t3(f):[](#l2.22)
f.set_result((1, 2, 3))[](#l2.23)
task = asyncio.Task(t1(), loop=self.loop)[](#l2.25)
val = self.loop.run_until_complete(task)[](#l2.26)
self.assertEqual(val, (1, 2, 3))[](#l2.27)
finally:[](#l2.28)
asyncio.tasks._DEBUG = old_debug[](#l2.29)
+ + class GatherTestsBase: def setUp(self):