What's the correct way to clean up after an interrupted event loop?
问题 I have an event loop that runs some co-routines as part of a command line tool. The user may interrupt the tool with the usual Ctrl + C , at which point I want to clean up properly after the interrupted event loop. Here's what I tried. import asyncio @asyncio.coroutine def shleepy_time(seconds): print("Shleeping for {s} seconds...".format(s=seconds)) yield from asyncio.sleep(seconds) if __name__ == '__main__': loop = asyncio.get_event_loop() # Side note: Apparently, async() will be deprecated