Message274547
Below code reproduces the problem. The resulting error is a RecursionError and it is very hard to trace that to the cause of the problem, which is the runner task and the stop task yielding from each other, forming a deadlock.
I think, an easy to make mistake like that should raise a clearer exception. And maybe I am mistaken, but it should in principle be possible for the event loop to detect a cyclic yield, right?
import asyncio
class A:
@asyncio.coroutine
def start(self):
self.runner_task = asyncio.ensure_future(self.runner())
@asyncio.coroutine
def stop(self):
self.runner_task.cancel()
yield from self.runner_task
@asyncio.coroutine
def runner(self):
try:
while True:
yield from asyncio.sleep(5)
except asyncio.CancelledError:
yield from self.stop()
return
def do_test():
@asyncio.coroutine
def f():
a = A()
yield from a.start()
yield from asyncio.sleep(1)
yield from a.stop()
asyncio.get_event_loop().run_until_complete(f()) |
|
Date |
User |
Action |
Args |
2016-09-06 10:16:54 | Max von Tettenborn | set | recipients:
+ Max von Tettenborn, gvanrossum, vstinner, yselivanov |
2016-09-06 10:16:54 | Max von Tettenborn | set | messageid: <1473157014.91.0.531687158456.issue27972@psf.upfronthosting.co.za> |
2016-09-06 10:16:54 | Max von Tettenborn | link | issue27972 messages |
2016-09-06 10:16:54 | Max von Tettenborn | create | |
|