I created a script that takes a .tab file and joins it to a shapefile. The script works perfectly but when it finishes, it gives me an unhandled exception which crashes Python.
I don't know what might be causing it but I think I have identify where it's happening. I wanted to ask if someone could help me identify the problem so I can fix it. I'm using ArcPy 10.1 and Python 2.7. I think it's happening in this part. For all the variables I get values prior to this portion of the script. I do the same calculation for other fields so this code repeats itself but for different columns.
#Create and calculate new fields
#Population
if(p == 1):
pop_calc = '!pop_20{}!-!pop_2010!'.format(year)
arcpy.AddField_management(outFeature, "pop_diff","LONG",15,"","","","")
arcpy.CalculateField_management(outFeature,'pop_diff',pop_calc,"PYTHON_9.3")
arcpy.AddField_management(outFeature, "popShare","DOUBLE",15,10,"","","")
popSharedTotal = 0
popFields = 'pop_diff'
with arcpy.da.SearchCursor(fc, popFields)as cursor:
for row in cursor:
popSharedTotal = row[0] + popSharedTotal
arcpy.AddField_management(outFeature, 'temp',"LONG",15,"","","","")
arcpy.CalculateField_management(outFeature,'temp',popSharedTotal,"PYTHON_9.3")
arcpy.CalculateField_management(outFeature,'popShare','[pop_diff]/[temp]',"VB")
arcpy.DeleteField_management(outFeature,'temp')
I can provide the entire script if needed but by commenting sections, this portion is what makes Python not close correctly when done with the script.
Best Answer
This is an simply an arcpy bug. You can try to avoid using the steps that are causing the crash, but it generally happens under different tools when used to process through a long list of data. The only workaround I have found is to make my script save its progress along the way to disk so if you restart the process, it knows where to pickup from. If you then disable windows debugger message by altering the registry (see below), you can then just repeatedly execute the script in cmd.exe until it completes the entire batch.
I know this is an awful workaround, but it is quite uncommon to have a python library kill off the python interpreter.