Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

How does one break the execution of a long-running process in the python console of ArcMap?

For example, how do you break a long iteration like the one below once it is started?

for i in range(1, 50):
  # some long process which takes over a minute to complete

I want to stop the process at any time I want by pressing a keyboard combination, clicking a button or something similar while the code I have input in the console window is running.

share|improve this question
By break do you mean do you mean force it to quit? –  R.K. Dec 20 '12 at 11:58
@R.K.: Yes, I want to force it to quit at any time I want, because I have (1) seen an undesired output, (2) have entered the wrong processing order, (3) any other reason. –  Alex Essilfie Dec 20 '12 at 12:57
Just checked the possible keyboard shortcuts. Ctrl + Z, Ctrl + C and ESC all don't work. You might need to use IDLE or another IDE to accomplish what you want. –  R.K. Dec 20 '12 at 13:02
use ctrl +Z in lx terminal for windows machine –  anurag 2 days ago

4 Answers 4

up vote 6 down vote accepted

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.

share|improve this answer
The ArcGIS Pro Python window lets you stop Python code while it's executing, due to technological limitations the ArcGIS 10.X window can't. –  Jason Scheirer Mar 6 at 3:09

This is the method I use:

  • create a small python script called
  • 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 file:

import os 

if os.path.exists(nameof_killfile): 
share|improve this answer
What is the script you call ""? –  Aaron Dec 20 '12 at 18:52
the kill_process script just makes an empty txt file with the correct name in the correct folder. –  mhoran_psprep Dec 20 '12 at 19:10
Could you please include a sample script in your post, so we can get a better idea of how this could help with the OP's question? –  Aaron Dec 20 '12 at 19:16
@mhoran_psprep: I've accepted R.K.'s answer because it answers the question (it is not possible unless in an IDE). +1 for your workaround. I guess I'll implement it in future. –  Alex Essilfie Dec 21 '12 at 9:30

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?

share|improve this answer
And of course, with a IDE like PyScripter, you can just add a "break point" at your "for...range" statement, run the script in "debug mode", and the IDE will automatically "pause" at the same point during the iterative process and allow you to inspect the results that have already been processed. –  RyanDalton Dec 20 '12 at 19:12

if you want to solve in pythonic way, try this:

import sys

or use:

raise SystemExit()

in detail:

import time
import sys

sTime= time.time()

if time.time() - sTime > 60:

i hope it helps you...

share|improve this answer
No, this is not what I want. I want to stop the process at any time I want by pressing a keyboard combination, clicking a button or something similar while the code I have input in the console window is running. I am aware of sys.exit() but that doesn't work when a loop or a similarly long process is running. –  Alex Essilfie Dec 20 '12 at 12:55
@Upvoters: this is not the answer I'm looking for. It does not answer my question. I want to break the execution of a statement (typically iteration) by pressing a keyboard combination or clicking a button or something similar. –  Alex Essilfie Dec 20 '12 at 13:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.