A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2015-December/142548.html below:

[Python-Dev] asyncio: how to interrupt an async def w/ finally: ( e.g. Condition.wait() )

[Python-Dev] asyncio: how to interrupt an async def w/ finally: ( e.g. Condition.wait() ) [Python-Dev] asyncio: how to interrupt an async def w/ finally: ( e.g. Condition.wait() )Matthias Urlichs matthias at urlichs.de
Sun Dec 20 00:29:40 EST 2015
On 20.12.2015 01:26, Kevin Conway wrote:
> async def coroutine():
>     try:
>         await Awaitable()
>         await Awaitable()
>     finally:
>         print('finally')
Try adding another "await Awaitable()" after the "finally:".

I have to take back my "doesn't print an error" comment, however;
there's another reference to the Condition.wait() generator (the task
asyncio.wait() creates to wrap the generator in), and the "Task was
destroyed but it is pending!" message got delayed sufficiently that I
missed it. (Dying test cases tend to spew many of these.)

Testcase:

    import asyncio
    import gc
    cond = asyncio.Condition()
    loop = asyncio.get_event_loop()

    async def main():
        async with cond:
            # asyncio.wait() does this, if we don't
            w = asyncio.ensure_future(cond.wait())
            await asyncio.wait([w],timeout=1)
            print(gc.get_referrers(w))
    loop.run_until_complete(main())

Time to refactor my code to do the wait/timeout outside the "async with
cond".

-- 
-- Matthias Urlichs

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4