Randomly occuring python errors in script

Discussion created by ablakey on Sep 6, 2013
Latest reply on Sep 8, 2013 by stacyrendall
I've got a long script that performs a bunch of different geoprocessing tasks. It creates a File GDB, creates empty feature classes and builds data, often with cursors.  1/2 the time I run the script, it always runs into errors about schema locks or simply fails to run a function that worked previously.

While my full code is longer and I don't want to share it all, this subsection will throw errors randomly. The latest is:

Traceback (most recent call last):
  File "C:\Users\ablakey\Documents\Projects\RapidQuotes\rq.py", line 66, in <module>
    arcpy.CalculatePolygonMainAngle_cartography("waterbodyBound", "angle","GEOGRAPHIC")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\cartography.py", line 350, in CalculatePolygonMainAngle
    raise e
arcgisscripting.ExecuteError: ERROR 000582: Error occurred during execution.

It's as if the code is stumbling over itself when it comes to locks. Is there something I'm missing to create an FC and then have it ready and unlocked when the next function tries to edit it?

# 0. Delete Previous Data
if arcpy.Exists("c:/Users/ablakey/Documents/Projects/RapidQuotes/geodata/rq.gdb"):  
arcpy.CreateFileGDB_management("c:/Users/ablakey/Documents/Projects/RapidQuotes/geodata", "rq.gdb")

# 0.1. Create Empty FCs
arcpy.CreateFeatureclass_management(ws,"pathLines", "POLYLINE", spatial_reference = spatial_reference)

# 1. Buffer Waterbody
arcpy.Buffer_analysis(waterbodyPoly,"waterbodyBuffer",0 - shorelineBuffer)

# 2. Get Bounding Box

# 3. Add "angle" Field

# 4. Calculate Angle
arcpy.CalculatePolygonMainAngle_cartography("waterbodyBound", "angle","GEOGRAPHIC")