This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Max von Tettenborn
Recipients Max von Tettenborn, gvanrossum, vstinner, yselivanov
Date 2016-09-06.10:16:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1473157014.91.0.531687158456.issue27972@psf.upfronthosting.co.za>
In-reply-to
Content
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())
History
Date User Action Args
2016-09-06 10:16:54Max von Tettenbornsetrecipients: + Max von Tettenborn, gvanrossum, vstinner, yselivanov
2016-09-06 10:16:54Max von Tettenbornsetmessageid: <1473157014.91.0.531687158456.issue27972@psf.upfronthosting.co.za>
2016-09-06 10:16:54Max von Tettenbornlinkissue27972 messages
2016-09-06 10:16:54Max von Tettenborncreate