Tuesday 28 March 2017

arcpy - What would cause a geoprocessing service to say "Cannot Open 'FeatureClass' Failed to Execute"?



I have a really basic geoprocessing script that's published to ArcGIS Server 10.2.2.


It basically just reads in a json object that's passed in as a parameter. The json just has attribute names and values, as well as a geometry in wkid 4326.


All it does is open an InsertCursor to create features in one specific feature class.


Nevermind asking me "All you want to do is create a bunch of features, why don't you do this in the rest endpoint?" Long story short, I tried several times using the jsapi, and even building my own geometries. In both cases, I got "d is not applied."


Anyway. This Geoprocessing script does work. But sometimes I check the logs and see "SEVERE: 'Cannot open SCHEMA.FEATURECLASS'. Failed to execute (Name of GP service). Failed to execute (name of GP Service).


What would cause this?? I noticed that on times where it works, it was very early in the day (5 AM). And then someone tried to use it around 10 AM and the script fails. From my DBMS knowledge, the only reasons I can think of why someone can't open a feature class for inserting:



  • Someone has a schema lock (I find this less likely since you usually can't get a schema lock on anything if the ArcGIS Server is running)

  • A database transaction is in progress (I don't see any evidence of this since the only other system that loads data into this database shows no records of any loading happening around the time of the error log

  • does arcpy.da.insertcursor fail to open if there's another insertcursor open simultaneously? (I hope not...)



Other info:



  • This is not a versioned feature class

  • The arcpy.env.workspace is set to an sde file that connects as the geodatabase admin. This connection is set to use the default version


  • Here are the properties on the service enter image description here


    #CODE SNIPPET - This is 90% of the business logic here
    loadCursor = arcpy.da.InsertCursor(Feature_Name, fields)
    oids = []


    for feature in FeaturesToAdd:
    geom = feature["geometry"]
    point = (geom["x"], geom["y"])
    attributes = feature["attributes"].values()
    attributes.append(point)
    row = tuple(attributes)
    print len(row)
    oid = loadCursor.insertRow(row)
    oids.append(oid)



    del loadCursor

    print oids


What else would cause arcpy not to be able to open a feature class for inserting?


Here's the basic code snippet for doing that:


loadCursor = arcpy.da.InsertCursor('SCHEMA.FEATURECLASS', ['field1','field2', 'field3', 'shape@XY']


there's nothing else that opens up any cursors, lists fields, queries the db. etc. This is the only line (not including loadCursor.insertRow())



Answer




does arcpy.da.insertcursor fail to open if there's another insertcursor open simultaneously? (I hope not...)





Yes it will fail, as this guarantees database integrity. From the ESRI guide on Cursors and Locking:





Insert and update cursors honor table locks set by ArcGIS applications. Locks prevent multiple processes from changing the same table at the same time.


Update and insert cursors cannot be created for a table or feature class if an exclusive lock exists for that dataset. The UpdateCursor or InsertCursor functions fail because of an exclusive lock on the dataset. If these functions successfully create a cursor, they apply an exclusive lock on the dataset so that two scripts cannot create an update or insert cursor on the same dataset.



A cursor can released by one of the following:




  • Including the cursor inside a with statement, which will guarantee the release of locks regardless of whether or not the cursor is successfully completed




  • Calling reset() on the cursor




  • The completion of the cursor

  • Explicitly deleting the cursor using Python's del statement



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...