[issue44594] AsyncExitStack.enter_async_context() is mishandling exception __context__

John Belmonte report at bugs.python.org
Sun Jul 11 20:56:20 EDT 2021


John Belmonte <john at neggie.net> added the comment:

demonstrating the difference for async case:

    import contextlib
    import trio
    
    async def background():
        assert False
    
    async def main1():
        async with trio.open_nursery() as nursery:
            nursery.start_soon(background)
            await trio.sleep_forever()
    
    async def main2():
        async with contextlib.AsyncExitStack() as stack:
            nursery = await stack.enter_async_context(trio.open_nursery())
            nursery.start_soon(background)
            await trio.sleep_forever()
    
    try:
        trio.run(main1)
    except BaseException as e:
        print('main1, context:', e.__context__)
    
    try:
        trio.run(main2)
    except BaseException as e:
        print('main2, context:', e.__context__)


----
main1, context: None
main2, context: Cancelled

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44594>
_______________________________________


More information about the Python-bugs-list mailing list