Select to view content in your preferred language

How to kill a notebook process

23514
19
11-19-2021 12:47 PM
ChrisCowin
Occasional Contributor

I've tried everything I can think of to kill a running notebook that is stuck in a loop and nothing works. The Interrupt Kernel button is always grayed out, tried restarting the kernel through the command prompt (P Key) but this doesnt seem to do anything either. The only way I've figured out how to stop the process is to kill the entire application in task manager.

19 Replies
edward33
Regular Contributor

In the notebook tab in the top banner you can click "interrupt kernel". I've done this a few times with success, unless ArcPro isn't responding at all, then I find this button can be greyed out.

edward33_0-1716570980572.png

 

EugeneSosnin_GSI
Occasional Contributor

You could run a command in CMD:

Taskkill /IM ArcGISPro.exe /F

It will instantly close ArcGIS PRO, with running Python too. You could save Notebook and Project when script is running, and then run the command.

HenriBrillon
Emerging Contributor

I am still experiencing this instability. Can we expect Esri to introduce reliable interrupt kernel functionality soon?

chris_del101
Regular Contributor

Me too. I run a notebook and it freezes and there is no way to unfreeze. Open and closing an application is not a legitimate solution to this problem. 

Interrupt kernel button is greyed out. Ending task does not work.

Kopczyknj_CDMSmith
New Contributor

Running 3.4.0 still a problem for me.  For those screenshotting the ribbon, here is what it looks like no matter which window you have active during the process.

Kopczyknj_CDMSmith
New Contributor

OK, I made a little headway troubleshooting.  For me, I was copy/pasting paths from the catalog tab over to the python window.  I noticed if I did the path copy/paste from a text file that I create before running the script and NOT the catalog window (while the script was running) I was able to maintain the Kernel interruption option.  I'm sure this has something to do with lock file management but maybe it will help others.

0 Kudos
JeffKaplan_Boston
Occasional Contributor

2025, and I am running into this issue as well. I am trying to write a notebook script that iterates through around 500 features with a searchcursor, and had to use task manager to end an accidental infinite loop.

JeffKaplan_Boston_0-1744902404235.png

The Interrupt Kernel button is greyed out for the whole time and the shortcut command doesn't do anything.

I am working in ArcGIS Pro 3.3, it would be great to know if this is an active bug, has been fixed in a later release, or is something Esri is looking into.

 

Melissa_B
Frequent Contributor

2025 and running ArcGIS Pro 3.5.2 - the interrupt kernel button is still greyed out during certain operations requiring Task Manager to end the process for the whole project.  I've gotten into the habit of testing all my loops with a break at the end so I can evaluate the first result before setting it loose completely. It would still be nice to be able to stop the occasional accidental infinite loop or unexpectedly long process though.  Did come across this bug in searching for a solution though: https://support.esri.com/en-us/bug/when-using-arcgis-notebooks-in-arcgis-pro-interrupting-bug-000132...  Since the interrupt kernel button is in the ribbon, maybe the issue is related?

OscarFitzpatrick
Occasional Contributor

Running 3.5.0, and still experiencing this issue in almost 2026! (Happy 4 year anniversary of this post 🙂)

JorgeAntunes
New Contributor

This is obviously not the desired solution and it's a bit ridiculous, but... it works.

While running an infinite while loop script in ArcGIS Pro, the only solution I came up with for stopping the script was creating a specific file in a specific folder and having the script check for its presence during the loop. If the file is present, the script halts.

I tried all the tips here and elsewhere without success. The thing is, the UI doesn't respond to any interaction during the script execution besides panning and zooming the map. So this is what I came up with, and although it is not perfect, it's way better than terminating the application—which, by the way, sometimes isn't even possible without forcing it via the Task Manager.

To make it a little more practical, I have a simple batch file in the same folder that creates the OINK.txt file, which I just double-click to stop the Python script. Other dynamics could be used to address this, just make sure you trigger the specific file that halts the script, or... wait for ESRI to fix this UI blocking issue.

import os
import time

# --- Setup Kill Switch (OINK) ---
# Gets the current directory where the script is running
current_folder = os.getcwd()
kill_file = os.path.join(current_folder, "OINK.txt")

# Clean up the file from previous runs, if it exists
if os.path.exists(kill_file):
    try:
        os.remove(kill_file)
    except Exception:
        pass

print(f"[SYSTEM] Process started.")
print(f"To gracefully stop the script, create an empty file named 'OINK.txt' in:")
print(f"-> {current_folder}\n")

# --- Execution ---
elapsed_seconds = 0
interval_seconds = 3

try:
    while True:
        # 1. Main task execution (e.g., printing the timer)
        print(f"Running... {elapsed_seconds} seconds have passed.")
        elapsed_seconds += interval_seconds

        # 2. The Kill Switch Logic
        # Breaks down the wait time into 1-second chunks to check for the file frequently
        stop_requested = False
        for _ in range(interval_seconds):
            if os.path.exists(kill_file):
                stop_requested = True
                break
            time.sleep(1)
            
        # 3. Break the infinite loop if the file is detected
        if stop_requested:
            print("\n[SYSTEM] OINK file detected! Executing ridiculous aborting operation...")
            break

    # 4. Clean exit and remove the trigger file
    if os.path.exists(kill_file):
        try:
            os.remove(kill_file)
        except Exception:
            pass
            
    print("[SYSTEM] Script terminated safely.")

except KeyboardInterrupt:
    print("\n[SYSTEM] Forced stop via keyboard (Ctrl+C).")

  

0 Kudos