Why do some tools generate exceptions only while debugging? In other words, when the tool is "run" in ArcMap (10.3.1), the process completes smoothly and as expected, but when "debug" is selected, an exception gets raised - most recently it was:
ExecuteError: ERROR 00464: Cannot get exclusive schema lock. Either being edited or in use by another application. Failed to execute (Near).
The offending call was the Near_analysis in line 24 in the code below
import arcpy from arcpy import env debug = arcpy.GetParameterAsText(2) if (debug == 'true'): mxdfile = arcpy.GetParameterAsText(3) mxd = arcpy.mapping.MapDocument(mxdfile) else: mxd = arcpy.mapping.MapDocument("CURRENT") mappolyfc = arcpy.GetParameterAsText(1) fcs = arcpy.GetParameter(0) dsource1 = fcs.workspacePath fcs = arcpy.GetParameterAsText(0).split(';') # feature classes multivalue parameter env.workspace = dsource1 f, fldlist = None, None # now process each feature class in fcs for fc in fcs: arcpy.AddMessage("Processing " +fc) result = arcpy.Near_analysis(fc,mappolyfc) ## ## omitted other code...... arcpy.RefreshTOC() result = arcpy.RefreshActiveView() del mxd
Such behavior (raising exceptions only in debug mode) have happened frequently on several projects with various geoprocessing tools and it starts to get wacky! Sometimes the behavior changes after version updates, too.
Any suggestions? Surely others are experiencing similar behavior?
in your omitted code section are there try except blocks? I don't know if it is IDE dependent, but I quit using them a long time ago and just learned how to read the errors that appear. I rapidly get the old "in use by other..." error message followed by the litany of the errors history. I have just gotten used to interpreting. I use Pythonwin and Pyscripter... can't say which throws the errors the best (if any)
those try except blocks are only useful, in my mind, in figuring out how to handle the exception. I just want to fix it and I personally haven't seen a need to carry on if something isn't going to work. Of