[New-bugs-announce] [issue27972] Confusing error during cyclic yield

Max von Tettenborn report at bugs.python.org
Tue Sep 6 06:16:54 EDT 2016

New submission from Max von Tettenborn:

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:
    def start(self):
        self.runner_task = asyncio.ensure_future(self.runner())

    def stop(self):
        yield from self.runner_task

    def runner(self):
            while True:
                yield from asyncio.sleep(5)
        except asyncio.CancelledError:
            yield from self.stop()

def do_test():
    def f():
        a = A()
        yield from a.start()
        yield from asyncio.sleep(1)
        yield from a.stop()


components: asyncio
messages: 274547
nosy: Max von Tettenborn, gvanrossum, haypo, yselivanov
priority: normal
severity: normal
status: open
title: Confusing error during cyclic yield
type: behavior
versions: Python 3.5

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list