Select to view content in your preferred language

Update cursor cannot acquire a lock

2150
3
Jump to solution
09-01-2022 02:44 PM
AlfredBaldenweck
MVP Regular Contributor

Hi all,

I'm trying to run an update cursor on a series of feature classes.

Each class has its own cursor, with different things going on in it.

Each one works fine, except the last feature class.

This feature class will work correctly maybe 2/9 times, otherwise giving the following error.

AlfredBaldenweck_0-1662067963028.png

RuntimeError: Cannot acquire a lock 

Sometimes it'll  work again if I run it a second time, or if I reopen the project, but neither of these is consistent.

Code sample below:

 

 

with arcpy.da.UpdateCursor(tmkFC, ['tmk_txt', 'Docs']) as cursor:
    for row in cursor:
        if row[0] in tmkDict:
            row[1] = "<br>".join(tmkDict[row[0]])
        else:
            row[1] = None
        cursor.updateRow(row)

 

 

 

  1.  It is on a network drive, in the same file gdb as the other feature classes
  2.  No one else is accessing the feature class right now.
  3. It occurs regardless of if it is the only thing getting updated, or if the other feature classes are also getting updated.
    1. Meaning I commented everything else out and this still occurs.
  4. This is the only feature class that has issues.
  5. I am not in an edit session, nor have any other edits been made prior to calling this cursor.
  6.  Someone else had a similar problem here, but there wasn't really any resolution for it. 

Does anyone have any ideas as to why this may be happening?

 

Edit: Found the error page, is not helpful in this case.: 160706: Cannot acquire a lock.—ArcGIS Pro | Documentation

Also, 7) this feature class has significantly more records than the others.

0 Kudos
1 Solution

Accepted Solutions
BrennanSmith1
Regular Contributor

It's probably not the same gremlin you're dealing with, but sometimes when I call cursors from a .pyt, I get random schema locks when the attribute table is open that go away when I close it.

View solution in original post

3 Replies
JohannesLindner
MVP Frequent Contributor

Spitballing reasons:

  • the FC is part of a service
  • for Enterprise (you said fgdb, but still) I get this error when I have the same FC from a different connection opened in the project
  • the FC is part of a locked Feature Dataset (if a FC in a FDS would be locked, the whole FDS is locked)

 

This is what the docs have to say:

  • Exclusive locks are applied when changes are made to a table or feature class. Editing and saving a feature class in a map, changing a table's schema, or using an insert cursor on a feature class in aPythonIDE are examples of when an exclusive lock is applied by ArcGIS.

Update and insert cursors cannot be created for a table or feature class if an exclusive lock exists for that dataset. TheUpdateCursororInsertCursorfunction fails 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.

Cursors supportwithstatements to reset iteration and aid in removal of locks. However, using adelstatement to delete the object or wrapping the cursor in a function to have the cursor object go out of scope should be considered to guard against all locking cases.

So, try deleting your cursors (outside of the with block) to be absolutely sure that they don't lock anything anymore:

 

with arcpy.da.XyzCursor(table, fields) as cursor:
    for row in cursor:
        pass
del cursor

 

 


Have a great day!
Johannes
0 Kudos
BrennanSmith1
Regular Contributor

It's probably not the same gremlin you're dealing with, but sometimes when I call cursors from a .pyt, I get random schema locks when the attribute table is open that go away when I close it.

AlfredBaldenweck
MVP Regular Contributor

I cannot believe it.

That was the problem.

For future reference, it must be closed, not just inactive.

Thanks!

0 Kudos