<?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: arcpy.management.CalculateField running into &amp;quot;Cannot acquire a lock&amp;quot; error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1551006#M73075</link>
    <description>&lt;P&gt;I'd just use UpdateCursor objects for this task:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

NewDlnLayer = "path/to/your/layer"
DlnChangedField = "DlnChangedField"
DlnOnParcelBorder = "DlnOnParcelBorder"

fields = [
    [
        DlnOnParcelBorder, #field name
        "TEXT",            #field type
        1                  #field length
    ],
    [
        DlnOnParcelBorder,
        "TEXT",
        1
    ],
]
#adding the fields
arcpy.management.AddFields(NewDlnLayer, fields)

#Calculating values into the fields using UpdateCursor
with arcpy.da.UpdateCursor(NewDlnLayer, [DlnChangedField, DlnOnParcelBorder]) as cursor:
    for row in cursor:
        row = ['N', 'N']
        cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you keep having issues, you could try using arcpy.da.Editor() context and checking the exceptions raised?&lt;/P&gt;</description>
    <pubDate>Tue, 22 Oct 2024 17:38:56 GMT</pubDate>
    <dc:creator>HaydenWelch</dc:creator>
    <dc:date>2024-10-22T17:38:56Z</dc:date>
    <item>
      <title>arcpy.management.CalculateField running into "Cannot acquire a lock" error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1550568#M73064</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a python notebook that I've been running in Pro v3.0 that compares a handful of point feature classes to two different versions of a polygon feature class and tells me which points are not in the same polygon in both versions.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem I am having is after adding columns to the point feature classes (via arcpy.management.AddField), I keep getting a "Cannot acquire a lock" error when I try to calculate values into those fields.&amp;nbsp; These feature classes are all in a file geodatabase that nobody else is using except me.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What do I need to do between the first CalculateField and the second to get this to work?&amp;nbsp; It is the same feature class involved both times.&lt;/P&gt;&lt;P&gt;I use CalculateField many times elsewhere in the notebook but after arcpy.management.SelectLayerByLocation (or ByAttribute).&amp;nbsp; This only is happening when it follows .AddField.&lt;/P&gt;&lt;P&gt;Here are the relevant sections of the notebook:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#adding the fields
arcpy.management.AddField(NewDlnLayer,DlnChangedField,"TEXT",field_length=1)
arcpy.management.AddField(NewDlnLayer,DlnOnParcelBorder,"TEXT",field_length=1)

#Calculating values into the fields

arcpy.management.CalculateField(NewDlnLayer,DlnChangedField,"'N'","PYTHON3")
arcpy.management.CalculateField(NewDlnLayer,DlnOnParcelBorder,"'N'","PYTHON3") #IT'S BEEN FAILING HERE&lt;/LI-CODE&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 19:09:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1550568#M73064</guid>
      <dc:creator>MichaelMarlatt1</dc:creator>
      <dc:date>2024-10-21T19:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.management.CalculateField running into "Cannot acquire a lock" error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1550570#M73065</link>
      <description>&lt;P&gt;If the attribute tables are open when you run your code, close them and see if that fixes it.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 18:16:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1550570#M73065</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-10-21T18:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.management.CalculateField running into "Cannot acquire a lock" error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1550584#M73067</link>
      <description>&lt;P&gt;I read that somewhere here and I made sure to have the tables closed.&amp;nbsp; It didn't make a difference unfortunately.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 19:08:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1550584#M73067</guid>
      <dc:creator>MichaelMarlatt1</dc:creator>
      <dc:date>2024-10-21T19:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.management.CalculateField running into "Cannot acquire a lock" error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1550593#M73068</link>
      <description>&lt;P&gt;Try&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/add-fields.htm" target="_blank"&gt;Add Fields (multiple) (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;although I suspect that adding the fields in two separate instances wouldn't be the cause of the lock&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 19:24:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1550593#M73068</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-10-21T19:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.management.CalculateField running into "Cannot acquire a lock" error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1550624#M73069</link>
      <description>&lt;P&gt;Hi Dan,&lt;/P&gt;&lt;P&gt;I tried using .AddFields.&amp;nbsp; It does its work faster than .AddField, but I am still having the same problem when trying to use .CalculateField afterwards.&amp;nbsp; I am now looking for some sort of a .Save() command that needs to be used after tools like .AddField, .AddFields, or .CalculateField that updates the feature class.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far ESRI's documentation is not helping much.&amp;nbsp; The page for the error is especially useless:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/tool-errors-and-warnings/160001-170000/tool-errors-and-warnings-160701-160725-160706.htm" target="_blank"&gt;160706: Cannot acquire a lock.—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I'll keep digging.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 20:22:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1550624#M73069</guid>
      <dc:creator>MichaelMarlatt1</dc:creator>
      <dc:date>2024-10-21T20:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.management.CalculateField running into "Cannot acquire a lock" error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1550874#M73072</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/136482"&gt;@MichaelMarlatt1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have a workspace set and is your NewDlnLayer referencing a map object or a workspace object?&lt;/P&gt;&lt;P&gt;More so how are you declaring that variable? It could be as simple as redeclaring your variable between the two operations but I have not had to do that before when running these commands.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do regularly use edit operations anytime I make changes to feature classes or map layers. It is just an added layer of protection I like to use to ensure my edits get applied properly. Check out this link below I think its the .Save() you were looking for:&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/editor.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/editor.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2024 13:57:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1550874#M73072</guid>
      <dc:creator>BrandonMcAlister</dc:creator>
      <dc:date>2024-10-22T13:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.management.CalculateField running into "Cannot acquire a lock" error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1551006#M73075</link>
      <description>&lt;P&gt;I'd just use UpdateCursor objects for this task:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

NewDlnLayer = "path/to/your/layer"
DlnChangedField = "DlnChangedField"
DlnOnParcelBorder = "DlnOnParcelBorder"

fields = [
    [
        DlnOnParcelBorder, #field name
        "TEXT",            #field type
        1                  #field length
    ],
    [
        DlnOnParcelBorder,
        "TEXT",
        1
    ],
]
#adding the fields
arcpy.management.AddFields(NewDlnLayer, fields)

#Calculating values into the fields using UpdateCursor
with arcpy.da.UpdateCursor(NewDlnLayer, [DlnChangedField, DlnOnParcelBorder]) as cursor:
    for row in cursor:
        row = ['N', 'N']
        cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you keep having issues, you could try using arcpy.da.Editor() context and checking the exceptions raised?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2024 17:38:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1551006#M73075</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2024-10-22T17:38:56Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.management.CalculateField running into "Cannot acquire a lock" error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1552522#M73095</link>
      <description>&lt;P&gt;I'll take a look at the editor class, thank you.&lt;/P&gt;&lt;P&gt;I'm not sure about the workspace but I think I'm working from a map object.&amp;nbsp; Here are the firs three cells of the notebook (the problem I'm having is ocurring in the third cell).&lt;/P&gt;&lt;P&gt;First Cell:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;'''Get set up'''
import arcpy
project = arcpy.mp.ArcGISProject("CURRENT")
#print("Map's name is " + project.listMaps()[0].name)
m = project.listMaps()[0] #Get the map
CurrentDlnLayer = m.listLayers('esriopsgis.GISOPSWRITER.DLN_NWD')[0]
CurrentParcelLayer = m.listLayers('GISOPSWRITER.MergedParcels')[0]
CurrentPoleLayer = m.listLayers('esriopsgis.GISOPSWRITER.Pole_ALL_NWD')[0]
CurrentSubstructLayer = m.listLayers('esriopsgis.GISOPSWRITER.Substruct_NWD')[0]
CurrentSubBoxLayer = m.listLayers('esriopsgis.GISOPSWRITER.Subbox_NWD')[0]

OldDate = '20241025'  #*************** CHANGE THIS TO MATCH THE DATE OF THE "OLD" DATA, YYYYmmdd
OldDlnLayer = m.listLayers('DLN_' + OldDate)[0] 
OldParcelLayer = m.listLayers('MergedParcels_' + OldDate)[0] 
OldPoleLayer = m.listLayers('Pole_ALL_NWD_' + OldDate)[0]
OldSubstructLayer = m.listLayers('Substruct_NWD_' + OldDate)[0]
OldSubBoxLayer = m.listLayers('Subbox_NWD_' + OldDate)[0]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second Cell:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;'''Copy DLN, Pole, Substruct, Subbox, and MergedParcels feature classes to project gdb. Creating a snapshot.'''
from datetime import date
todays_date = date.today().strftime("%Y%m%d") #format current date as yyyymmdd
#print(todays_date)
#create names of new layers
DlnNewName = 'DLN_' + todays_date
ParcelsNewName = 'MergedParcels_' + todays_date
PolesNewName = 'Pole_ALL_NWD_' + todays_date
SubstructNewName = 'Substruct_NWD_' + todays_date
SubBoxNewName = 'Subbox_NWD_' + todays_date

#copy layers
arcpy.conversion.FeatureClassToFeatureClass(CurrentDlnLayer,project.defaultGeodatabase,DlnNewName)
arcpy.conversion.FeatureClassToFeatureClass(CurrentParcelLayer,project.defaultGeodatabase,ParcelsNewName)
arcpy.conversion.FeatureClassToFeatureClass(CurrentPoleLayer,project.defaultGeodatabase,PolesNewName) 
arcpy.conversion.FeatureClassToFeatureClass(CurrentSubstructLayer,project.defaultGeodatabase,SubstructNewName)
arcpy.conversion.FeatureClassToFeatureClass(CurrentSubBoxLayer,project.defaultGeodatabase,SubBoxNewName)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Third cell: (the error has been occurring on line 23)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;'''Add fields to DLN, MergedParcel, Pole, Substruct, Subbox copies and calculate them to 'N'
***Only need to do this with the NEW parcels and DLNs '''
NewDlnLayer = m.listLayers(DlnNewName)[0]
DlnChangedField = 'dlg_geom_changed'
DlnOnParcelBorder = 'dlg_on_parcel_border'

NewParcelLayer = m.listLayers(ParcelsNewName)[0]
ParcelChangedField = 'parcel_geom_changed'

NewPoleLayer = m.listLayers(PolesNewName)[0]
PoleChangedField = 'pole_geom_changed'
PoleOnParcelBorder = 'pole_on_parcel_border'

NewSubstructLayer = m.listLayers(SubstructNewName)[0]
SubstructChangedField = 'substruct_geom_changed'
SubstructOnParcelBorder = 'substruct_on_parcel_border'

NewSubboxLayer = m.listLayers(SubBoxNewName)[0]
SubboxChangedField = 'subbox_geom_changed'
SubboxOnParcelBorder = 'subbox_on_parcel_border'

arcpy.management.AddField(NewDlnLayer,DlnChangedField,"TEXT",field_length=1)
arcpy.management.CalculateField(NewDlnLayer,DlnChangedField,"'N'","PYTHON3")
arcpy.management.AddField(NewDlnLayer,DlnOnParcelBorder,"TEXT",field_length=1)
arcpy.management.CalculateField(NewDlnLayer,DlnOnParcelBorder,"'N'","PYTHON3")

arcpy.management.AddField(NewParcelLayer,ParcelChangedField,"TEXT",field_length=1)
arcpy.management.CalculateField(NewParcelLayer,ParcelChangedField,"'N'","PYTHON3")

arcpy.management.AddField(NewPoleLayer,PoleChangedField,"TEXT",field_length=1)
arcpy.management.CalculateField(NewPoleLayer,PoleChangedField,"'N'","PYTHON3")
arcpy.management.AddField(NewPoleLayer,PoleOnParcelBorder,"TEXT",field_length=1)
arcpy.management.CalculateField(NewPoleLayer,PoleOnParcelBorder,"'N'","PYTHON3")

arcpy.management.AddField(NewSubstructLayer,SubstructChangedField,"TEXT",field_length=1)
arcpy.management.CalculateField(NewSubstructLayer,SubstructChangedField,"'N'","PYTHON3")
arcpy.management.AddField(NewSubstructLayer,SubstructOnParcelBorder,"TEXT",field_length=1)
arcpy.management.CalculateField(NewSubstructLayer,SubstructOnParcelBorder,"'N'","PYTHON3")

arcpy.management.AddField(NewSubboxLayer,SubboxChangedField,"TEXT",field_length=1)
arcpy.management.CalculateField(NewSubboxLayer,SubboxChangedField,"'N'","PYTHON3")
arcpy.management.AddField(NewSubboxLayer,SubboxOnParcelBorder,"TEXT",field_length=1)
arcpy.management.CalculateField(NewSubboxLayer,SubboxOnParcelBorder,"'N'","PYTHON3")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 19:47:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-management-calculatefield-running-into-quot/m-p/1552522#M73095</guid>
      <dc:creator>MichaelMarlatt1</dc:creator>
      <dc:date>2024-10-25T19:47:30Z</dc:date>
    </item>
  </channel>
</rss>

