I have several standalone scripts that create a list of shapefiles to process (or coverages in one of the scripts). Sometimes my script crashes after it processes three files, sometimes ten, sometimes with just one to go. In some cases, it's quite complex operations, but sometimes, it's just a simple arcpy.Union_analysis(inShp, outShp) or with CalculateField_management().

It seems totally random because I just delete the outputs before restarting my scripts and it may or may not work the next time. Eventually it works, sometimes on the first try, but other times, I could have to retry it 2 or 5 or 10 times.

Any ideas what could cause this?
Should I clean or delete something from memory that could cause a crash?

It's maddening... I added Errors/Exceptions Handling (with the traceback module to get python and ArcPy message). I simply put all my code inside my loop in the "try:" and my loop increment as well. When there's a error, my counter don't increment because the "i=i+1" is after when the error occured. So, when the loop restart, my "i" is the same as previous and it restart processing the same files that cause the error... And then it works! See this screenshot, Green, first try, yellow, 2nd and blue, ok and processing the next...
–
fgcartographixAug 10 '12 at 15:21

Could that be that the script is too quick and arcpy outputs necessary for the next step arent already available? Clearly the code itself isn't a problem? Maybe adding a "time.sleep(1)" could help?
–
fgcartographixAug 10 '12 at 15:23

You'd likely need to use arcpy.Delete_management() as opposed to del
–
RoyNov 16 '12 at 19:50

I used Delete_management() for the output of all tool that create another file as output and del for "in_memory" datasets. The two tools that cause much problem are "arcpy.FeatureClassToShapefile_conversion(inFeaturePolygon, outFolder)" and "arcpy.Project_management(inFeatureClassPolygon, outFeatureClassPolygon, outCoordSys)". The thing is that since it's looping, the values of my variables are reassigned each time... Of course, if "Foncier Quebec" (Quebec Land Parcels) could just give us anything except .e00...
–
fgcartographixNov 19 '12 at 13:11