How to manually break statement execution in Python window of ArcMap?

Just tested it and ESC doesn't work either. ArcGIS just freezes for a moment and then continues. There doesn't seem to be a way to do force quit it once it runs in the ArcGIS Python console. You can't kill it using Task Manager either as the Python process doesn't show up there.

If you really want to be able to force quit it, you might want to consider using an IDE like IDLE rather than doing it in the ArcGIS Python console. In IDLE for example, you can use Ctrl + Z or Ctrl + C to terminate the execution.


This is the method I use:

  • create a small python script called kill_processx.py
  • When run kill_processx creates a small test file called stop_processx.txt.
  • At the top or bottom of the loop in the main program check to see if the stop_processx.txt exists.
  • If it does exist, execute any cleanup routines you need, then stop gracefully.
  • Delete the stop_processx.txt file

example of a kill_processx.py file:

import os 
nameof_killfile="stop_processx.txt"

if os.path.exists(nameof_killfile): 
    os.remove(nameof_killfile) 
else:
    killit=open(nameof_killfile,"w") 
    killit.close()

It is bad practice to force shutdown using brute force tactics. Rather, as @Aragon pointed out you should add error handling to your script to isolate components and/or stop the script if certain conditions are not met. As @R.K. points out, the ArcGIS python console is next to worthless for running complex scripts and, in practice, should be reserved for simple operations--stick with IDLE, pythonwin, pyscripter or any of the host of other IDEs. Here are discussions related to your question:

How do I use sys.exit(0) in an arcpy script to exit early without having an error message show up?

Terminating a Python script

How to stop a command or prompt in Python?