Cancel event in Python Gp tools with arcpy

Discussion created by d.iseneggeresri-ch-esridist Employee on Apr 25, 2013
Latest reply on May 22, 2013 by d.iseneggeresri-ch-esridist
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:
            for workspace in workspace_list:
               counter += 1
                msg = str.format("{0}.workspace: {1} ", counter, workspace)
                whole_msg += msg

        except arcpy.ExecuteError:
            msg = str.format("arcpy.ExecuteError: {0}", arcpy.GetMessages())
        # Return any other type of error
            msg = str.format("Non-tool error occurred: {0}", arcpy.GetMessages())

Thank You in advance!