I have some geoprocessing services published to ArcGIS Server. I have noticed that every time a request is made, a great amount of time (1 to 3 seconds) is needed to establish the connection to the Geodatabase Entreprise workspace.
For instance, if I use a SearchCursor in a GP Service, a lot of time is spent setting arcpy.env.workspace. It's not faster to define the workspace in the SearchCursor in_table parameter.
I would like to know if it's possible to define a default workspace at the service instances level in order that when a service instance is created, the connection to a Geodatabase Entreprise workspace is made and kept open until the instance is closed?
Solved! Go to Solution.
After some testing, I confirm that using layer (.lyr) as the in_table parameter in arcpy.da.SearchCursor is much faster than using the path to the feature class.
However, to be able to use fields name tokens such SHAPE@ or SHAPE@JSON you have to create a new layer class with the arcpy.mapping module.
layer_path = r"c:\\temp\\myLayer.lyr" with arcpy.da.SearchCursor(arcpy.mapping.Layer(layer_path), ["*"]) as cursor: for row in cursor: print row
I have to give you a thumb up as none of ESRI's doc or webinar I have searched gave a clear example of how to use Layer as the input, because there're some many definition/interpolation of what a Layer is, not to mention have to convert it to Layer class using arcpy.mapping to in order to use the field tokens. thank you.