So I've been experimenting with modularized tools (see here). So far it's working really well, but one of the biggest issues is that seemingly randomly, adding this modular toolbox to a project will cause ArcPro to freeze up. Nothing is showing up in Diagnostic Monitor and the toolbox just silently fails to load and Arc never releases control back to the user with an error unless you force close it.
When using a helper tool that runs the ImportToolbox function, it will occasionally fail with several dozen attempts at importing the toolbox, but it's inconsistent. Also once the toolbox is added to the project it works fine and even with the import reloads, it refreshes in about half a second.
One thing that I think could be causing the issue is that I'm using a wrapper class for the Tools that pre-calculates a lot of project related data into object parameters:
class Tool(object):
"""
Base class for all tools that use python objects to build parameters
"""
def __init__(self) -> None:
"""
Tool Description
@self.project: arcpy project object
@self.project_location: path to the project
@self.project_name: name of the project
@self.default_gdb: path to the default gdb
@self.design_gdb = archelp.get_databases(self.project_location, database_name="lld_design.gdb")
@self.design_gdb: path to the design gdb
@self.design_features: dictionary of design features
@self.params: tool parameters (set with archelp.get_parameters())
"""
# Tool parameters
self.label = "Tool"
self.description = "Base class for all tools that use python objects to build parameters"
self.canRunInBackground = False
self.category = "Unassigned"
# Project variables
self.project = arcpy.mp.ArcGISProject("CURRENT")
self.project_location = self.project.homeFolder
self.project_name = os.path.basename(self.project_location)
# Database variables
self.default_gdb = self.project.defaultGeodatabase
self.design_gdb = archelp.get_databases(self.project_location, database_name="lld_design.gdb")
if self.design_gdb:
self.design_gdb = self.design_gdb[0]
self.design_features = archelp.walk_database(self.design_gdb ,dataset="Design_Features")
else:
self.design_gdb = None
self.design_features = None
# Parameters
self.params = {}
return
So Every tool is implementing this __init__() with a super.__init__() call. Could this be freaking ArcPro out? as in every subtool of the toolbox is running this init function constantly for every tool? I'm making queries in it, and when I refresh the toolbox it only seems to run those queries once for the whole toolbox and again when I open the tool, but maybe the import action is hitting some sort of confusion with this?
I know I'm using Python Tools well outside their normal operating functionality, but any hints on what exactly could be causing these import problems from someone with more knowledge about how Arc handles python tools would be great.