I successful import a custom toolbox. Inside the custom toolbox are multiple toolsets. The toolbox is "NWI_Toolbox", the toolset is "Combined Tools", and the tool is "Combined Wetland Polygonal Tools". This tool essentially runs all of the individual tools in a separate toolset named "Individual Polygonal Tools".
When I do this manually, the tool takes about 40 seconds to run. When I do it via Python, it imports successfully and then takes about 80 minutes. What might explain this discrepancy?
Notice in the code below that I call the imported toolbox as "QC_Tools" - this is the alias of the toolbox. I have also tried importing the toolbox with a designated module name and calling it that way, but get the same result.
nwi_toolbox = r'C:\projects\Tools\Round1\NWI_Toolbox.pyt'
arcpy.ImportToolbox(nwi_toolbox)
arcpy.QC_Tools.combinedPolyTools(ak_schema_gdb, 'AK', 'DE', True)
Is the slowdown spread across the execution of the tools? Or is it directly at the start of each tool's execution? It could be a repeated license check that the tool is running or some repeated initialization of the tool. I'd also try combining all the existing scripts into one tool to see if the slowdown still occurs.
80 Minutes is a massive slowdown though and it's hard to tell exactly what could be causing it without some test cases or logging info.
The following code seems to work fine for me (speed wise when compared to manual runs).
We have the same workflow: run all tools in this toolbox.
# we need path to python toolbox
pyt_path = r"C:\path\to\toolbox\toolboxName.pyt"
arcpy.ImportToolbox(pyt_path, "myToolbox")
# get parameters (each tool takes a single parameter, the geodatabase path)
gdb_path = str(parameters[0].value)
# Run all tools
arcpy.AddMessage(dir(arcpy.myToolbox))
for t in dir(arcpy.myToolbox):
# Skip the tools we do not want to run
if t.startswith("_") or t.startswith("RunAll"):
continue
arcpy.AddMessage("Running {}".format(t))
try:
tool = getattr(arcpy.myToolbox, t)
tool(gdb_path)
except Exception as e:
arcpy.AddError("{} failed...".format(t))
arcpy.AddError(e)
arcpy.AddError("-------------")