Can I have multiple open arcpy.da.InsertCursor at the same time?

11164
6
Jump to solution
10-03-2012 10:42 AM
TimDine
Occasional Contributor II
Is this possible or do you have to delete one cursor before opening another?

I create the first cursor, make a row, and insert it.  I make the second cursor, make a row, attempt to insert it, and I get the error "workspace already in transaction mode". 

While creating cursors in the new form is much faster (I measured 10X) it should still be faster to have all of the cursors I`m going to use created once rather than 50000 times.  I`m loading features in a random order from randomly ordered XML files.
Tags (2)
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor
Is this possible or do you have to delete one cursor before opening another?


The arcpy.da.SearchCursor" rel="nofollow" target="_blank">http://resources.arcgis.com/en/help/main/10.1/... doc says right up front:

Opening simultaneous insert and/or update operations on the same workspace using different cursors requires the start of an edit session.

View solution in original post

0 Kudos
6 Replies
curtvprice
MVP Esteemed Contributor
Is this possible or do you have to delete one cursor before opening another?


The arcpy.da.SearchCursor" rel="nofollow" target="_blank">http://resources.arcgis.com/en/help/main/10.1/... doc says right up front:

Opening simultaneous insert and/or update operations on the same workspace using different cursors requires the start of an edit session.
0 Kudos
ClayPerry
New Contributor
I think if you are adding features from various sources into a single feature class, you only need one insert cursor running to handle the record insertion.  The source files would require individual search cursors to pull the information to be added by the insert cursor.  You would probably want some sort of loop to run through the input files that does the following: creates a search cursor, grabs some info, adds the gathered information via the insert cursor to your new feature class, and closes the search cursor.  But like a previous post said, apparently you can't open multiple insert/update cursors without and edit session being open.
0 Kudos
TimDine
Occasional Contributor II
So I did miss that note, I see it right at the top of the arcpy.da.insertcursor documentation as well now.  In the mean time I managed to get an error about the feature class not being editable outside an edit session which got me onto an edit session for an unrelated reason.  I now have a far simplified chunk of code that gives me the same error.  "workspace already in transaction mode". 

import arcpy

edit = arcpy.da.Editor(r'C:/Projects/GISPROD_ElectricDistribution_Extract.gdb')

edit.startEditing(False,False)

theIC = arcpy.da.InsertCursor(r'C:/Projects/GISPROD_ElectricDistribution_Extract.gdb/electric/servicepoint',['PHASEDESIGNATION', 'WORKORDERID', 'SUBTYPECD', 'PLACEMENTCONFIDENCE', 'SHAPE@'])
theIC.insertRow(['7', '280773', '1', '90', arcpy.Point(292840.72313, 4818098.69548)])

edit.stopEditing(False)


Thoughts? There is a geometric network buried in there, but there are not objects that are not straight arcgis object classes that I am aware of.
0 Kudos
TimDine
Occasional Contributor II
I believe it's data related.  I think I've got it sorted.

Marking the original answer as correct.
0 Kudos
DouglasHall
New Contributor III
Just FYI, I can't create and delete 3 insert cursors squentially without getting the following error. (Sequentially meaning that I'm creating and deleting the cursor before creating the next one).

RuntimeError: workspace already in transaction mode


Upon creating the third cursor and attempting to insertRow(), I get the error.

It doesn't matter if I'm in the editing session or not.

I can comment out any one of the 3 cursor insert blocks and the other 2 will work.

Using a with clause or cursor = ..., doesn't matter
with arcpy.da.InsertCursor('Points_Geom', ["PointID", 'SHAPE@XY']) as cursor:
    cursor.insertRow((123458, (4364181.91, 263840.13)))


or

cursor = arcpy.da.InsertCursor('Points_Geom', ["PointID", 'SHAPE@XY'])
cursor.insertRow((123458, (4364181.91, 263840.13)))
del cursor
0 Kudos
PaulSchneider
Occasional Contributor
Try this link as another possible solution to this error.
0 Kudos