<?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 Runtime Error: Cannot Acquire Lock in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/runtime-error-cannot-acquire-lock/m-p/1408117#M70288</link>
    <description>&lt;P&gt;So I have this tool I've written which takes geocoded address and selects the parcel they are in then updates the shape coordinates and several fields. However on I keep getting a Runtime Error: Cannot Acquire Lock on line 73 edit.stopEditing(True)&lt;/P&gt;&lt;P&gt;According to ESRI this error happens so infrequently that there are no help docs or solutions for this issue.&amp;nbsp;&lt;/P&gt;&lt;P&gt;See code below&lt;/P&gt;&lt;P&gt;#Define project&lt;BR /&gt;arcpy.SetProgressor("step", "Setting up tool", 0, 100, 1) #sets tool progression label and loading bar&lt;/P&gt;&lt;P&gt;import os #import operating system&lt;BR /&gt;import datetime #imports datetime system library&lt;/P&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject("Current") #current arcpro project&lt;BR /&gt;MP = aprx.activeMap #current open map view&lt;BR /&gt;Geocode = MP.listLayers("CSRR_PI_Coords_Geocoded")[0] #create object for Geocoded File&lt;BR /&gt;Parcels = MP.listLayers("Parcels (Block and Lot) Data - For Internal Purposes Only - Do Not Distribute")[0] #create parcel object&lt;BR /&gt;User = os.getlogin() #Gets windows user names&lt;BR /&gt;defaultgdb = aprx.defaultGeodatabase #Gets default geodatabase&lt;BR /&gt;arcpy.env.workspace = defaultgdb #Sets workspace equal to default geodatabase&lt;BR /&gt;workspace = arcpy.env.workspace #Creates variable to access workspace easily&lt;BR /&gt;edit = arcpy.da.Editor(workspace) #creates edit variable&lt;/P&gt;&lt;P&gt;lyrlist = MP.listLayers()&lt;BR /&gt;i = 0&lt;BR /&gt;while i &amp;lt; len(lyrlist):&lt;BR /&gt;if "Multiple_Parcel_PIs" in lyrlist[i].name:&lt;BR /&gt;MultiParcel = MP.listLayers("Multiple_Parcel_PIs")[0] #create object for Multiple PI File&lt;BR /&gt;break&lt;BR /&gt;else:&lt;BR /&gt;arcpy.AddMessage("No Multiple Parcel PI feature class was detected.")&lt;BR /&gt;i += 1&lt;/P&gt;&lt;P&gt;#Move geocoded points with a point address match and a 100 percent match and did not Tie to parcel centroid&lt;BR /&gt;MP.clearSelection() #Clears all selected features in the map&lt;BR /&gt;arcpy.management.SelectLayerByAttribute(Geocode, where_clause = "(Addr_type = 'PointAddress' And Score = 100 And Status = 'M' And ProChecker IS NULL) Or ProChecker = 2")&lt;BR /&gt;count = arcpy.management.GetCount(Geocode)&lt;BR /&gt;if int(str(count)) &amp;gt; 0:&lt;BR /&gt;intervaltime = []&lt;BR /&gt;now = datetime.datetime.now() #gets time block started&lt;BR /&gt;Geocode.definitionQuery = "(Addr_type = 'PointAddress' And Score = 100 And Status = 'M' And ProChecker IS NULL) Or ProChecker = 2"&lt;/P&gt;&lt;P&gt;arcpy.SetProgressorLabel("Moving geocoded points with address match")&lt;BR /&gt;arcpy.SetProgressorPosition(1)&lt;BR /&gt;cursor = arcpy.da.SearchCursor(Geocode, ["ObjectID"]) #searches through CSRR_PI_Coord_Geocodes and gets all ObjIDs&lt;BR /&gt;array = cursor._as_narray() #Turns cursor into an array&lt;/P&gt;&lt;P&gt;i = 0&lt;BR /&gt;while i &amp;lt; len(array): #Loops through each spot in the array&lt;BR /&gt;loopnow = datetime.datetime.now()&lt;BR /&gt;arcpy.management.SelectLayerByAttribute(Geocode, where_clause = "ObjectID = " + str(array[i][0])) #Selects Feature by Object ID in layer CSRR_PI_Coords_Geocoded&lt;BR /&gt;arcpy.management.SelectLayerByLocation( #Select the parcel that intersects the feature selected in CSRR_PI_Coords_Geocoded&lt;BR /&gt;in_layer = Parcels,&lt;BR /&gt;overlap_type = "INTERSECT",&lt;BR /&gt;select_features = Geocode,&lt;BR /&gt;search_distance = None,&lt;BR /&gt;selection_type = "NEW_SELECTION",&lt;BR /&gt;invert_spatial_relationship = "NOT_INVERT"&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;#Get parcel centroid and pams pin&lt;BR /&gt;Pcursor = arcpy.da.SearchCursor(Parcels, ["SHAPE@TRUECENTROID", "Pams_Pin"]) #Gets parcel centroid and Pams Pin from attribute table&lt;BR /&gt;Parray = Pcursor._as_narray() #creates an array for the search cursor&lt;BR /&gt;centroid_east = Parray[0][0][0] #Gets centroid easting value&lt;BR /&gt;centroid_north = Parray[0][0][1] #Gets centroid northing value&lt;BR /&gt;parcel = Parray[0][1] #Creates number string to pass through calculate field&lt;BR /&gt;&lt;BR /&gt;edit.startEditing(False, False) #Starts an editing session&lt;BR /&gt;#updates shape Easting and Northing, with parcel centroid&lt;BR /&gt;upcursor = arcpy.da.UpdateCursor(Geocode, ["SHAPE@"])&lt;BR /&gt;for row in upcursor: #updateRow method only works in for loop&lt;BR /&gt;pt = arcpy.Point(centroid_east, centroid_north) #creates an arcpy point with parcel easting and northing&lt;BR /&gt;row = [pt] #makes the point equal to row&lt;BR /&gt;upcursor.updateRow(row) #Updates feature geometry&lt;BR /&gt;del upcursor&lt;BR /&gt;parcelcursor = arcpy.da.UpdateCursor(Geocode, ["parcel_data"])&lt;BR /&gt;for row in parcelcursor:&lt;BR /&gt;row[0] = parcel&lt;BR /&gt;parcelcursor.updateRow(row)&lt;BR /&gt;del parcelcursor&lt;BR /&gt;checkcursor = arcpy.da.UpdateCursor(Geocode, ["ProChecker"])&lt;BR /&gt;for row in checkcursor:&lt;BR /&gt;row = [4]&lt;BR /&gt;checkcursor.updateRow(row)&lt;BR /&gt;del checkcursor&lt;BR /&gt;edit.stopEditing(True) #Save edits and ends edit session&lt;BR /&gt;loopend = datetime.datetime.now()&lt;BR /&gt;loopelapse = loopend - loopnow&lt;BR /&gt;intervaltime.append(loopelapse.total_seconds())&lt;BR /&gt;i += 1&lt;BR /&gt;length = len(intervaltime)&lt;BR /&gt;total = sum(intervaltime)&lt;BR /&gt;mean = total/length&lt;BR /&gt;end = datetime.datetime.now()&lt;BR /&gt;elapsed = end - now&lt;BR /&gt;arcpy.AddMessage(str(len(array)) + " Geocoded address were within a parcel and moved to the centroid. This process took " + str(elapsed) + " with an average of" + str(mean) + " seconds per record.")&lt;/P&gt;&lt;P&gt;#Clears all defintion queries&lt;BR /&gt;Geocode.updateDefinitionQueries(None)&lt;/P&gt;&lt;P&gt;#Calculate fields for records that were moved to parcel centroid&lt;BR /&gt;arcpy.management.SelectLayerByAttribute(Geocode, where_clause = "ProChecker = 4") #Select points that were moved to parcel centroid&lt;BR /&gt;count = arcpy.management.GetCount(Geocode)&lt;BR /&gt;arcpy.SetProgressorLabel("Calculating Fields with Batch Update Codes") #changes tool progress label&lt;BR /&gt;arcpy.SetProgressorPosition(1) #resets progressor to beginning&lt;BR /&gt;if int(str(count)) &amp;gt; 0:&lt;BR /&gt;edit.startEditing(False, False)&lt;BR /&gt;upcursor = arcpy.da.UpdateCursor(Geocode, ["locational_comments", "updated_by", "coordinate_system_code", "coordinate_source_type_code", "coordinate_source_org_code", "coordinate_source_ref_code", "location_quality_type_code"])&lt;BR /&gt;for row in upcursor:&lt;BR /&gt;row[0] = "center of site (GIS Parcel Centroid)"&lt;BR /&gt;row[1] = str(User)&lt;BR /&gt;row[2] = "01"&lt;BR /&gt;row[3] = "11"&lt;BR /&gt;row[4] = "14"&lt;BR /&gt;row[5] = "36"&lt;BR /&gt;row[6] = "40"&lt;BR /&gt;upcursor.updateRow(row)&lt;BR /&gt;del upcursor&lt;BR /&gt;edit.stopEditing(True)&lt;BR /&gt;&lt;BR /&gt;#Calculates Date time this feature was updated&lt;BR /&gt;arcpy.management.CalculateField( #Calculates Date time this feature was updated&lt;BR /&gt;in_table = Geocode,&lt;BR /&gt;field = "updated_on",&lt;BR /&gt;expression = "datetime.datetime.now()",&lt;BR /&gt;expression_type = "PYTHON3",&lt;BR /&gt;code_block = "",&lt;BR /&gt;field_type = "TEXT",&lt;BR /&gt;enforce_domains = "NO_ENFORCE_DOMAINS"&lt;BR /&gt;)&lt;BR /&gt;else:&lt;BR /&gt;arcpy.AddMessage("No fields were calculated, and no PI's had valid Parcel Information")&lt;/P&gt;&lt;P&gt;arcpy.AddMessage("Step 3 completed proceed with manual placement.")&lt;/P&gt;</description>
    <pubDate>Wed, 10 Apr 2024 18:33:56 GMT</pubDate>
    <dc:creator>BrandonMcAlister</dc:creator>
    <dc:date>2024-04-10T18:33:56Z</dc:date>
    <item>
      <title>Runtime Error: Cannot Acquire Lock</title>
      <link>https://community.esri.com/t5/python-questions/runtime-error-cannot-acquire-lock/m-p/1408117#M70288</link>
      <description>&lt;P&gt;So I have this tool I've written which takes geocoded address and selects the parcel they are in then updates the shape coordinates and several fields. However on I keep getting a Runtime Error: Cannot Acquire Lock on line 73 edit.stopEditing(True)&lt;/P&gt;&lt;P&gt;According to ESRI this error happens so infrequently that there are no help docs or solutions for this issue.&amp;nbsp;&lt;/P&gt;&lt;P&gt;See code below&lt;/P&gt;&lt;P&gt;#Define project&lt;BR /&gt;arcpy.SetProgressor("step", "Setting up tool", 0, 100, 1) #sets tool progression label and loading bar&lt;/P&gt;&lt;P&gt;import os #import operating system&lt;BR /&gt;import datetime #imports datetime system library&lt;/P&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject("Current") #current arcpro project&lt;BR /&gt;MP = aprx.activeMap #current open map view&lt;BR /&gt;Geocode = MP.listLayers("CSRR_PI_Coords_Geocoded")[0] #create object for Geocoded File&lt;BR /&gt;Parcels = MP.listLayers("Parcels (Block and Lot) Data - For Internal Purposes Only - Do Not Distribute")[0] #create parcel object&lt;BR /&gt;User = os.getlogin() #Gets windows user names&lt;BR /&gt;defaultgdb = aprx.defaultGeodatabase #Gets default geodatabase&lt;BR /&gt;arcpy.env.workspace = defaultgdb #Sets workspace equal to default geodatabase&lt;BR /&gt;workspace = arcpy.env.workspace #Creates variable to access workspace easily&lt;BR /&gt;edit = arcpy.da.Editor(workspace) #creates edit variable&lt;/P&gt;&lt;P&gt;lyrlist = MP.listLayers()&lt;BR /&gt;i = 0&lt;BR /&gt;while i &amp;lt; len(lyrlist):&lt;BR /&gt;if "Multiple_Parcel_PIs" in lyrlist[i].name:&lt;BR /&gt;MultiParcel = MP.listLayers("Multiple_Parcel_PIs")[0] #create object for Multiple PI File&lt;BR /&gt;break&lt;BR /&gt;else:&lt;BR /&gt;arcpy.AddMessage("No Multiple Parcel PI feature class was detected.")&lt;BR /&gt;i += 1&lt;/P&gt;&lt;P&gt;#Move geocoded points with a point address match and a 100 percent match and did not Tie to parcel centroid&lt;BR /&gt;MP.clearSelection() #Clears all selected features in the map&lt;BR /&gt;arcpy.management.SelectLayerByAttribute(Geocode, where_clause = "(Addr_type = 'PointAddress' And Score = 100 And Status = 'M' And ProChecker IS NULL) Or ProChecker = 2")&lt;BR /&gt;count = arcpy.management.GetCount(Geocode)&lt;BR /&gt;if int(str(count)) &amp;gt; 0:&lt;BR /&gt;intervaltime = []&lt;BR /&gt;now = datetime.datetime.now() #gets time block started&lt;BR /&gt;Geocode.definitionQuery = "(Addr_type = 'PointAddress' And Score = 100 And Status = 'M' And ProChecker IS NULL) Or ProChecker = 2"&lt;/P&gt;&lt;P&gt;arcpy.SetProgressorLabel("Moving geocoded points with address match")&lt;BR /&gt;arcpy.SetProgressorPosition(1)&lt;BR /&gt;cursor = arcpy.da.SearchCursor(Geocode, ["ObjectID"]) #searches through CSRR_PI_Coord_Geocodes and gets all ObjIDs&lt;BR /&gt;array = cursor._as_narray() #Turns cursor into an array&lt;/P&gt;&lt;P&gt;i = 0&lt;BR /&gt;while i &amp;lt; len(array): #Loops through each spot in the array&lt;BR /&gt;loopnow = datetime.datetime.now()&lt;BR /&gt;arcpy.management.SelectLayerByAttribute(Geocode, where_clause = "ObjectID = " + str(array[i][0])) #Selects Feature by Object ID in layer CSRR_PI_Coords_Geocoded&lt;BR /&gt;arcpy.management.SelectLayerByLocation( #Select the parcel that intersects the feature selected in CSRR_PI_Coords_Geocoded&lt;BR /&gt;in_layer = Parcels,&lt;BR /&gt;overlap_type = "INTERSECT",&lt;BR /&gt;select_features = Geocode,&lt;BR /&gt;search_distance = None,&lt;BR /&gt;selection_type = "NEW_SELECTION",&lt;BR /&gt;invert_spatial_relationship = "NOT_INVERT"&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;#Get parcel centroid and pams pin&lt;BR /&gt;Pcursor = arcpy.da.SearchCursor(Parcels, ["SHAPE@TRUECENTROID", "Pams_Pin"]) #Gets parcel centroid and Pams Pin from attribute table&lt;BR /&gt;Parray = Pcursor._as_narray() #creates an array for the search cursor&lt;BR /&gt;centroid_east = Parray[0][0][0] #Gets centroid easting value&lt;BR /&gt;centroid_north = Parray[0][0][1] #Gets centroid northing value&lt;BR /&gt;parcel = Parray[0][1] #Creates number string to pass through calculate field&lt;BR /&gt;&lt;BR /&gt;edit.startEditing(False, False) #Starts an editing session&lt;BR /&gt;#updates shape Easting and Northing, with parcel centroid&lt;BR /&gt;upcursor = arcpy.da.UpdateCursor(Geocode, ["SHAPE@"])&lt;BR /&gt;for row in upcursor: #updateRow method only works in for loop&lt;BR /&gt;pt = arcpy.Point(centroid_east, centroid_north) #creates an arcpy point with parcel easting and northing&lt;BR /&gt;row = [pt] #makes the point equal to row&lt;BR /&gt;upcursor.updateRow(row) #Updates feature geometry&lt;BR /&gt;del upcursor&lt;BR /&gt;parcelcursor = arcpy.da.UpdateCursor(Geocode, ["parcel_data"])&lt;BR /&gt;for row in parcelcursor:&lt;BR /&gt;row[0] = parcel&lt;BR /&gt;parcelcursor.updateRow(row)&lt;BR /&gt;del parcelcursor&lt;BR /&gt;checkcursor = arcpy.da.UpdateCursor(Geocode, ["ProChecker"])&lt;BR /&gt;for row in checkcursor:&lt;BR /&gt;row = [4]&lt;BR /&gt;checkcursor.updateRow(row)&lt;BR /&gt;del checkcursor&lt;BR /&gt;edit.stopEditing(True) #Save edits and ends edit session&lt;BR /&gt;loopend = datetime.datetime.now()&lt;BR /&gt;loopelapse = loopend - loopnow&lt;BR /&gt;intervaltime.append(loopelapse.total_seconds())&lt;BR /&gt;i += 1&lt;BR /&gt;length = len(intervaltime)&lt;BR /&gt;total = sum(intervaltime)&lt;BR /&gt;mean = total/length&lt;BR /&gt;end = datetime.datetime.now()&lt;BR /&gt;elapsed = end - now&lt;BR /&gt;arcpy.AddMessage(str(len(array)) + " Geocoded address were within a parcel and moved to the centroid. This process took " + str(elapsed) + " with an average of" + str(mean) + " seconds per record.")&lt;/P&gt;&lt;P&gt;#Clears all defintion queries&lt;BR /&gt;Geocode.updateDefinitionQueries(None)&lt;/P&gt;&lt;P&gt;#Calculate fields for records that were moved to parcel centroid&lt;BR /&gt;arcpy.management.SelectLayerByAttribute(Geocode, where_clause = "ProChecker = 4") #Select points that were moved to parcel centroid&lt;BR /&gt;count = arcpy.management.GetCount(Geocode)&lt;BR /&gt;arcpy.SetProgressorLabel("Calculating Fields with Batch Update Codes") #changes tool progress label&lt;BR /&gt;arcpy.SetProgressorPosition(1) #resets progressor to beginning&lt;BR /&gt;if int(str(count)) &amp;gt; 0:&lt;BR /&gt;edit.startEditing(False, False)&lt;BR /&gt;upcursor = arcpy.da.UpdateCursor(Geocode, ["locational_comments", "updated_by", "coordinate_system_code", "coordinate_source_type_code", "coordinate_source_org_code", "coordinate_source_ref_code", "location_quality_type_code"])&lt;BR /&gt;for row in upcursor:&lt;BR /&gt;row[0] = "center of site (GIS Parcel Centroid)"&lt;BR /&gt;row[1] = str(User)&lt;BR /&gt;row[2] = "01"&lt;BR /&gt;row[3] = "11"&lt;BR /&gt;row[4] = "14"&lt;BR /&gt;row[5] = "36"&lt;BR /&gt;row[6] = "40"&lt;BR /&gt;upcursor.updateRow(row)&lt;BR /&gt;del upcursor&lt;BR /&gt;edit.stopEditing(True)&lt;BR /&gt;&lt;BR /&gt;#Calculates Date time this feature was updated&lt;BR /&gt;arcpy.management.CalculateField( #Calculates Date time this feature was updated&lt;BR /&gt;in_table = Geocode,&lt;BR /&gt;field = "updated_on",&lt;BR /&gt;expression = "datetime.datetime.now()",&lt;BR /&gt;expression_type = "PYTHON3",&lt;BR /&gt;code_block = "",&lt;BR /&gt;field_type = "TEXT",&lt;BR /&gt;enforce_domains = "NO_ENFORCE_DOMAINS"&lt;BR /&gt;)&lt;BR /&gt;else:&lt;BR /&gt;arcpy.AddMessage("No fields were calculated, and no PI's had valid Parcel Information")&lt;/P&gt;&lt;P&gt;arcpy.AddMessage("Step 3 completed proceed with manual placement.")&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2024 18:33:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtime-error-cannot-acquire-lock/m-p/1408117#M70288</guid>
      <dc:creator>BrandonMcAlister</dc:creator>
      <dc:date>2024-04-10T18:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Runtime Error: Cannot Acquire Lock</title>
      <link>https://community.esri.com/t5/python-questions/runtime-error-cannot-acquire-lock/m-p/1408121#M70289</link>
      <description>&lt;P&gt;Make sure the &lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/please-change-attribute-table-open-constitutes-a/idi-p/1360990" target="_blank" rel="noopener"&gt;attribute&lt;/A&gt; table is &lt;A href="https://community.esri.com/t5/arcgis-pro-questions/pro-3-1-3-running-an-update-cursor-on-a-feature/m-p/1339224" target="_blank" rel="noopener"&gt;closed&lt;/A&gt; when running the update cursor.&lt;/P&gt;&lt;P&gt;I kid you not, it will cause issues if you have more than 199 records in your table. (&lt;STRONG&gt;&lt;EM&gt;BUG-000113027)&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;That's going to be the easiest to test, so start there.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2024 18:37:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtime-error-cannot-acquire-lock/m-p/1408121#M70289</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-04-10T18:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: Runtime Error: Cannot Acquire Lock</title>
      <link>https://community.esri.com/t5/python-questions/runtime-error-cannot-acquire-lock/m-p/1408166#M70290</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/458875"&gt;@AlfredBaldenweck&lt;/a&gt;&amp;nbsp;I can't believe that worked....&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2024 19:53:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtime-error-cannot-acquire-lock/m-p/1408166#M70290</guid>
      <dc:creator>BrandonMcAlister</dc:creator>
      <dc:date>2024-04-10T19:53:03Z</dc:date>
    </item>
  </channel>
</rss>

