""" Prior to a fix, when signalled with SIGINT, this script will sometimes get stuck and only one of the test coroutines will be cancelled successfully. """ import asyncio async def test(name): try: while True: await asyncio.sleep(0) except asyncio.CancelledError: print(f'{name} has been cancelled successfully :)') async def main(): print('Interrupt me!') await asyncio.gather(test('A'), test('B')) if __name__ == '__main__': try: # Using debug to increase the chance of the bug to occur asyncio.run(main(), debug=True) except KeyboardInterrupt: print('Done')