[issue30083] Asyncio: GeneratorExit + strange exception

Guilherme Salgado report at bugs.python.org
Fri Sep 18 06:56:44 EDT 2020


Guilherme Salgado <gsalgado at gmail.com> added the comment:

I've also been affected by this and found that if you use asyncio.run() the coroutine is interrupted with a CancelledError as you'd expect. The following script shows that

=======================
import asyncio

async def handle_connection(reader, writer):
    try:
        await reader.readexactly(42)
    except BaseException as err:
        print('Interesting: %r.' % err)
        raise
    finally:
        writer.close()

async def main():
    listener = await asyncio.start_server(handle_connection, '127.0.0.1', 8888)
    try:
        async with listener:
            await listener.serve_forever()
    except KeyboardInterrupt:
        print('KeyboardInterrupt')

asyncio.run(main())
=============================================

----------
nosy: +salgado

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


More information about the Python-bugs-list mailing list