In GP-tools written in C# (ArcObjects) we can listen for the Cancel-event and react on that. I wonder if there is anything similar in Python GP-tools applying arcpy. I googled that issue and the only thing I found was the Cancel-method on the Result-Object (so that you can ask the state of the result of a GP-tool, i.e. if it was canceled). I'm aware that you can cancel GP-tools running in the background in the Result Window, but this Cancel-event is catched by the system and therefore the developer or the GP-tool cannot react on that.
Further I tried to catch the arcpy.ExecuteError within the canceled Python GP-script with the following statement, but no exception was catched:
try:
for workspace in workspace_list:
counter += 1
msg = str.format("{0}.workspace: {1} ", counter, workspace)
whole_msg += msg
arcpy.AddMessage(msg)
except arcpy.ExecuteError:
msg = str.format("arcpy.ExecuteError: {0}", arcpy.GetMessages())
arcpy.AddError(msg)
# Return any other type of error
except:
msg = str.format("Non-tool error occurred: {0}", arcpy.GetMessages())
arcpy.AddError(msg)
Thank You in advance!