I have a Geoprocessing Service that is complicated, but the issue I'm having revolves around a few very simple steps. I'm trying to take in a path to a feature class that sits within SDE, create a temporary feature layer out of it (arcpy.MakeFeatureLayer_management), and then use a search cursor (arcpy.da.SearchCursor) to count the records in the feature class. I am not using ArcMap or anything outside of arcpy for this, the layer is stored in-memory and dumped after being used. The script itself works fine up until the point that new data is added and then the results become inconsistent with the actual data.
Here is an example of the issue:
The only way I've discovered that the model will display the correct record count when run from Desktop is to close/open all ArcGIS Desktop applications and re-run it. Likewise, for the Geoprocessing Service to display the correct record count, I must restart or republish the Geoprocessing Service.
I'm hoping this issue has a simple resolution, but I'm scratching my head over it as of right now. If someone needs sample code, I can provide it, but the first paragraph is the script in a nutshell.
I suspect the issue is with the SearchCursor not being disposed of on completion of it's duties. if you aren't preceding the search cursor with a "with" like this:
with arcpy.da.SearchCursor(fc, fields) as cursor
:
then you'll need to be sure to do del on the variable assigned to the cursor. like this
cursor = arcpy.da.SearchCursor(fc, fields)
for row in cursor:
...
del cursor
you can also try in the same script simultaneously to get the count using arcpy.GetCount_management(fc) to see if the issue is with the cursor or with the connection.
here's a link to the getcount_management help page: ArcGIS Desktop