I'm new to Python and ArcGIS.
I've written a script (Python 3.9.16, installed with ArcGIS Pro 3.1.2) that updates a single numeric field in a Utility Networks Feature Service using an UpdateCursor, but at some point the script hangs. It can be after 5000 updates, or 200,000 - I can't see a pattern, even when repeating on the same data set.
There are around 600,000 rows in the UpdateCursor. It should take about 22 hours, but I haven't seen it run for more than 7 hours before it hangs.
I assume it's necessary to commit every so often, so I call this after each 1000 updates:
def flush( ed 😞
global edit
if edit is not None:
edit.stopOperation()
edit.stopEditing(True)
edit.startEditing(False, True)
edit.startOperation()
The first three operations take around 1 second in total, startOperation takes around 120 seconds after each 1000 updateRow operations (the 1000 cursor.updateRow(row) executions take around 10 seconds).
Time rises linearly when increasing the interval. I also tried calling stopEditing and startEditing less frequently - for example after every 2000, or 5000 updates, but the time per 1000 features was unchanged and it didn't seem to affect when the script started to hang.
When it hangs, it is during edit.startOperation() or edit.stopOperation()
It's running in the test environment and nothing else is running here. When doing such updates in the production environment it has to be outside of working hours, otherwise ArcGIS Pro is extremely slow.
Does anyone have any suggestions - apart from splitting the update task into smaller batches? If this was a database, setting a column value for 600,000 rows would take no time at all.
arcpy.SignInToPortal(urlTest, usernameTest, passwordTest)
fc = serviceUrlTest
workspace = os.path.dirname(fc)
edit = arcpy.da.Editor(workspace, true) # versioned
edit.startEditing(False, True)
edit.startOperation()