Avatar ·

asyncio: correct shutdown does not work

📁 Advanced Python Topics, question, Error, example, python3, asyncio, web, AI, game

I'm having the same problem again. Previously, all tanks were under my control, and I could manually close them. But the trouble is: I needed websockets here. In the examples, proper shutdown is not implemented:

start_server = websockets.serve(hello, 'localhost', 8765) asyncio.get_event_loop().run_until_complete(start_server) asyncio.get_event_loop().run_forever()

I played with examples, and yes, with Ctrl+C, it crashes if there is a connected client:

$ python websocket_server.py ^CKeyboardInterruptException ignored in: Task was destroyed but it