<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Update cursor cannot acquire a lock in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/update-cursor-cannot-acquire-a-lock/m-p/1209302#M65478</link>
    <description>&lt;P&gt;I cannot believe it.&lt;/P&gt;&lt;P&gt;That was the problem.&lt;/P&gt;&lt;P&gt;For future reference, it must be closed, not just inactive.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Fri, 02 Sep 2022 19:02:45 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2022-09-02T19:02:45Z</dc:date>
    <item>
      <title>Update cursor cannot acquire a lock</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-cannot-acquire-a-lock/m-p/1208916#M65468</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm trying to run an update cursor on a series of feature classes.&lt;/P&gt;&lt;P&gt;Each class has its own cursor, with different things going on in it.&lt;/P&gt;&lt;P&gt;Each one works fine, except the last feature class.&lt;/P&gt;&lt;P&gt;This feature class will work correctly maybe 2/9 times, otherwise giving the following error.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_0-1662067963028.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50184iF6E0169AFAFD4788/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_0-1662067963028.png" alt="AlfredBaldenweck_0-1662067963028.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;RuntimeError: Cannot acquire a lock&lt;/EM&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sometimes it'll&amp;nbsp; work again if I run it a second time, or if I reopen the project, but neither of these is consistent.&lt;/P&gt;&lt;P&gt;Code sample below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.UpdateCursor(tmkFC, ['tmk_txt', 'Docs']) as cursor:
    for row in cursor:
        if row[0] in tmkDict:
            row[1] = "&amp;lt;br&amp;gt;".join(tmkDict[row[0]])
        else:
            row[1] = None
        cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&amp;nbsp;It is on a network drive, in the same file gdb as the other feature classes&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;No one else is accessing the feature class right now.&lt;/LI&gt;&lt;LI&gt;It occurs regardless of if it is the only thing getting updated, or if the other feature classes are also getting updated.&lt;OL&gt;&lt;LI&gt;Meaning I commented everything else out and this still occurs.&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;This is the only feature class that has issues.&lt;/LI&gt;&lt;LI&gt;I am not in an edit session, nor have any other edits been made prior to calling this cursor.&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;Someone else had a similar &lt;A href="https://community.esri.com/t5/python-questions/i-am-getting-an-error-quot-cannot-acquire-a-lock/td-p/118094" target="_blank" rel="noopener"&gt;problem here&lt;/A&gt;, but there wasn't really any resolution for it.&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Does anyone have any ideas as to why this may be happening?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: Found the error page, is not helpful in this case.:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/2.9/tool-reference/tool-errors-and-warnings/160001-170000/tool-errors-and-warnings-160701-160725-160706.htm" target="_blank" rel="noopener"&gt;160706: Cannot acquire a lock.—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Also, 7) this feature class has significantly more records than the others.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2022 22:07:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-cannot-acquire-a-lock/m-p/1208916#M65468</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-09-01T22:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: Update cursor cannot acquire a lock</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-cannot-acquire-a-lock/m-p/1209030#M65470</link>
      <description>&lt;P&gt;Spitballing reasons:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;the FC is part of a service&lt;/LI&gt;&lt;LI&gt;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&lt;/LI&gt;&lt;LI&gt;the FC is part of a locked Feature Dataset (if a FC in a FDS would be locked, the whole FDS is locked)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what the &lt;A href="https://pro.arcgis.com/de/pro-app/2.8/arcpy/get-started/data-access-using-cursors.htm" target="_blank" rel="noopener"&gt;docs&lt;/A&gt; have to say:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;UL&gt;&lt;LI&gt;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 a&lt;SPAN class=""&gt;Python&lt;/SPAN&gt;IDE are examples of when an exclusive lock is applied by ArcGIS.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Update and insert cursors cannot be created for a table or feature class if an exclusive lock exists for that dataset. The&lt;SPAN class=""&gt;&lt;A href="https://pro.arcgis.com/de/pro-app/2.8/arcpy/functions/updatecursor.htm" target="_blank" rel="noopener"&gt;UpdateCursor&lt;/A&gt;&lt;/SPAN&gt;or&lt;SPAN class=""&gt;&lt;A href="https://pro.arcgis.com/de/pro-app/2.8/arcpy/functions/insertcursor.htm" target="_blank" rel="noopener"&gt;InsertCursor&lt;/A&gt;&lt;/SPAN&gt;function 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.&lt;/P&gt;&lt;P&gt;Cursors support&lt;SPAN class=""&gt;with&lt;/SPAN&gt;statements to reset iteration and aid in removal of locks. However, using a&lt;SPAN class=""&gt;del&lt;/SPAN&gt;statement 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.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So, try deleting your cursors (outside of the with block) to be absolutely sure that they don't lock anything anymore:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.XyzCursor(table, fields) as cursor:
    for row in cursor:
        pass
del cursor&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 06:25:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-cannot-acquire-a-lock/m-p/1209030#M65470</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-09-02T06:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: Update cursor cannot acquire a lock</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-cannot-acquire-a-lock/m-p/1209081#M65471</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 19:28:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-cannot-acquire-a-lock/m-p/1209081#M65471</guid>
      <dc:creator>BrennanSmith1</dc:creator>
      <dc:date>2022-09-02T19:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Update cursor cannot acquire a lock</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-cannot-acquire-a-lock/m-p/1209302#M65478</link>
      <description>&lt;P&gt;I cannot believe it.&lt;/P&gt;&lt;P&gt;That was the problem.&lt;/P&gt;&lt;P&gt;For future reference, it must be closed, not just inactive.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 19:02:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-cannot-acquire-a-lock/m-p/1209302#M65478</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2022-09-02T19:02:45Z</dc:date>
    </item>
  </channel>
</rss>

