Open
Description
Bug report
Bug description:
import asyncio
import logging
logging.basicConfig(level=logging.DEBUG)
async def myfunc(i):
logging.info("start %r", i)
try:
await asyncio.sleep(i)
except BaseException as e:
logging.error("caught in myfunc %r == %r", i, e)
logging.info("done myfunc %r %r", i, asyncio.get_running_loop())
async def pas():
try:
await myfunc(3)
await myfunc(4)
await myfunc(5)
await myfunc(6)
await myfunc(7)
except BaseException as e:
logging.error("caught in pas %r", e)
logging.info("done pas")
async def main():
try:
await pas()
except BaseException as e:
logging.error("caught in main %r", e)
logging.info("done main")
if __name__ == "__main__":
try:
asyncio.run(main(), debug=True)
except:
logging.exception("caught in __main__")
logging.error("program ended.")after pressing ctrl+c once, myfunc() caught CancelledError and loop is running and all code can finish normally;
after pressing ctrl+c twice, myfunc() caught CancelledError and loop is running and all code can finish normally;
after pressing ctrl+c thrice, myfunc() caught GeneratorExit(), but loop and the "program" is already closed before it.
excepted:
after pressing ctrl+c more than 2 times, it should be consistent as before.
OR
the KeyboardInterrupt should propaganda to the asyncio.Runner as _on_sigint() of it raised after pressing twice ctrl+c
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
Windows

