I am trying to build more fail-management logic into some of the GP services I develop. As a part of the business logic within the script tool I build, I write some data into the tables and thus lock access to certain parts of the geodatabase to let the currently running GP task to be executed undisturbed.
However, in case there are some issues which will force the GP service instance or ArcGIS Server Windows service to crash (something that is out of my hands), I want to be able to perform some clean-up work (release locks, clean-up scratch geodatabases, write to tables, etc). This is where I usually use
finally: statement when developing Python script tools for use in ArcGIS Desktop.
However, the GP service does not seem to reach the
finally: if it is timed-out or crashed.
The Python script tool source code is below:
import arcpy import time try: arcpy.AddMessage("Hello 1 second") time.sleep(10) arcpy.AddMessage("Hello after 10 sec") except: pass finally: arcpy.AddMessage("GP service timed out!")
I have run this tool in ArcMap:
Trying to run the GP service task (published from the tool result) that of GP service with time-out time for 9 seconds:
So the GP service is not able to reach
finally statement and print
"Hello after 10 sec". If this is not possible to implement within the
finally: statement in Python script tool source code, how would you approach this otherwise?