You should be able to just do a sub try...except statement around the thing that fails, like so:# Analyze
try:
env.workspace = dbconnection
fclist = arcpy.ListFeatureClasses() # <-- executes as expected
for fc in fclist:
arcpy.Analyze_management(fc,'BUSINESS;FEATURE;ADDS;DELETES')
output.write(" " + fc + " has been analyzed\n")
try:
fdlist = arcpy.ListFeatureDatasets() # <-- FAIL!!!
except: # if you know the error, put it there, i.e. except ExecuteError:
fdlist = None
if fdlist is not None:
for fd in fdlist:
arcpy.Analyze_management(fd,'BUSINESS;FEATURE;ADDS;DELETES')
output.write(" " + fd + " has been analyzed\n")
tablist = arcpy.ListTables() # <-- Doesn't execute
for tab in tablist:
arcpy.Analyze_management(tab,'BUSINESS')
output.write(" " + tab + " has been analyzed\n")
output.write(" arcpy.analyze finished successfully\n")
except:
output.write("!!arcpy.analyze didn't work right\n")
err_list = str(sys.exc_info())
for err in err_list.split('\\n'):
output.write(" " + err + "\n")
The if statement stops it running the analysis if the dataset couldn't be found. You can copy this to the other ones as well, if there is any possibility your data set may not include feature classes or tables...I think I once had Arc hang indefinitely on a script with a sub try...except, but I was doing that as well as sub functions and multiprocessing, so it may have been related to doing those as well.Let me know how you get on, as there are plenty of other ways to do this (if it does have a problem).