Why does the asyncio’s event loop suppress the KeyboardInterrupt on Windows?

There is workaround for Windows. Run another corouting which wake up loop every second and allow loop to react on keyboard interrupt Example with Echo server from asyncio doc async def wakeup(): while True: await asyncio.sleep(1) loop = asyncio.get_event_loop() coro = loop.create_server(EchoServerClientProtocol, ‘127.0.0.1’, 8888) server = loop.run_until_complete(coro) # add wakeup HACK loop.create_task(wakeup()) try: loop.run_forever() except … Read more

Why can’t I handle a KeyboardInterrupt in python?

Asynchronous exception handling is unfortunately not reliable (exceptions raised by signal handlers, outside contexts via C API, etc). You can increase your chances of handling the async exception properly if there is some coordination in the code about what piece of code is responsible for catching them (highest possible in the call stack seems appropriate … Read more

In Matlab, is it possible to terminate a script, but save all its internal variables to workspace?

MATLAB versions 2016a and later If you are using post 2016a versions of Matlab there is actually a pause button that appears when you run the script (as described by @pedre). This allows you to pause the script, inspect variables and then resume afterwards. Make sure to check out the next section as this may … Read more

Why doesn’t this Python keyboard interrupt work? (in PyCharm)

I know this is an old question, but I ran into the same problem and think there’s an easier solution: In PyCharm go to “Run”https://stackoverflow.com/”Edit Configurations” and check “Emulate terminal in output console”. PyCharm now accepts keyboard interrupts (make sure the console is focused). Tested on: PyCharm 2019.1 (Community Edition)

threading ignores KeyboardInterrupt exception

Try try: thread=reqthread() thread.daemon=True thread.start() while True: time.sleep(100) except (KeyboardInterrupt, SystemExit): print ‘\n! Received keyboard interrupt, quitting threads.\n’ Without the call to time.sleep, the main process is jumping out of the try…except block too early, so the KeyboardInterrupt is not caught. My first thought was to use thread.join, but that seems to block the main … Read more

Keyboard Interrupts with python’s multiprocessing Pool

This is a Python bug. When waiting for a condition in threading.Condition.wait(), KeyboardInterrupt is never sent. Repro: import threading cond = threading.Condition(threading.Lock()) cond.acquire() cond.wait(None) print “done” The KeyboardInterrupt exception won’t be delivered until wait() returns, and it never returns, so the interrupt never happens. KeyboardInterrupt should almost certainly interrupt a condition wait. Note that this … Read more