
Instead of hitting the KeyboardInterrupt catch statement, the script aborts abruptly, spitting out the following message:įorrtl: error (200): program aborting due to control-C event Under my ArcGIS 9.3.1 SP2/Windows XP SP3 environment, there is an issue with catching the KeyboardInterrupt exception if the arcgisscripting module is loaded.

We can reset the behavior of Ctrl + C to system default with following code.The KeyboardInterrupt exception - thrown when Ctrl-C, or Ctrl-Break on some machines, are pressed in a Python console window - is commonly used to gracefully break out of long-process loops, allowing your script to perform cleanup, logging etc, before exiting. I think, therefor, the PowerShell console that is a child process of Visual Studio IDE is also ignoring the Ctrl + C.Īfter thinking for a while, I tried to solve this issue by calling SetConsoleCtrlHandler Win32 API in the PowerShell console in-process. I guess, Visual Studio IDE (or any extensions live in it) calls SetConsoleCtrlHandler Win32 API to ignore to default behavior of Ctrl + C key pressing. This Win32 API allows a Win32 process to customize the behavior of Ctrl + C key is pressed.Īnd, this is an important point, the document says the effect of changing this behavior inherits to the child process! Only the PowerShell which is a child process of Visual Studio IDE has the problem.Īfter for a long hour my investigation with internet searching, I found SetConsoleCtrlHandler Win32 API. Pressing Ctrl + C keys can terminate a command when it is running.

In the PowerShell console which is opened NOT from Visual Studio IDE, such as from start menu or from Windows Explorer menu or from "Run" box or etc., Ctrl + C is working very fine expectedly.


Recently, I registered the command for launching PowerShell console at > menu in Visual Studio IDE, with the keyboard shortcut: Ctrl+P, Ctrl+S. I'm a developer who usually uses Visual Studio IDE on Windows OS.
