I recommend following the advice of @Vince:
If the script is run within the geoprocessing framework, and checks
are done in the app for the cancel button being pushed, then you can
handle this gracefully. If it's a standalone Idle (or other IDE)
interpreter, then a break might work. After that you're falling back
to killing the Python interpreter or Desktop session. I try always
add a check for a "stop.now" file at the top of my list processing
(if os.path.exists('stop.now'): break
), so I have a graceful way to
exit long-running loops.
or that of @FelixIP:
It's possible if you are using progressor bar.
I have not tested but I think both would work.
if os.path.exists('stop.now'): break
), so I have a graceful way to exit long-running loops.