Hello,
I have a python toolbox, that has the following tools:

Some of these scripts use the same procedures, so I moved those procedures to the top of the file above all of the individual classes. Which seems to make sense, I don't have exact copies of the same procedure inside each class, fewer lines of code, smaller file...
The top of the file looks like this (this is not all the procedures that are at the top just the first few):
import arcpy
import os
import re
import shutil
import configparser
import subprocess
from time import gmtime, strftime
def OpenAprx(aprx):
#open the passed in mxd file in a new arcmap instance
arcpy.AddMessage('Opening: {}'.format(aprx))
subprocess.Popen([r'C:\Program Files\ArcGIS\Pro\bin\ArcGISPro.exe',aprx])
def CreateImage(prj, mapName, lyrsOn, lyrsOff, lyrExtent, lytName, mapScale, pngFilePath):
arcpy.AddMessage('CreateImage start {}'.format(strftime("%H:%M:%S", gmtime())))
arcpy.AddMessage('prj: {}'.format(prj))
SetLayers(prj, mapName, lyrsOn, 'on')
arcpy.AddMessage('SetLayers ON completed {}'.format(strftime("%H:%M:%S", gmtime())))
arcpy.AddMessage('len lyrsOff: {}'.format(len(lyrsOff)))
if len(lyrsOff) > 0:
SetLayers(prj, mapName, lyrsOff, 'off')
arcpy.AddMessage('SetLayers OFF completed {}'.format(strftime("%H:%M:%S", gmtime())))
ExportImage(prj, mapName, lyrExtent, lytName, mapScale, pngFilePath)
arcpy.AddMessage('ExportImage completed {}'.format(strftime("%H:%M:%S", gmtime())))
def SetLayers(prj, mapName, lyrs, status):
arcpy.AddMessage('SetLayers prj = {}'.format(prj))
aprx = arcpy.mp.ArcGISProject(prj)
m = aprx.listMaps(mapName)[0]
for lyr in m.listLayers():
if lyr.name.upper() in lyrs:
if status == 'on':
lyr.visible = True
else:
lyr.visible = False
#aprx.save()
del aprx
This all seems great to me but the problem is the code executes way slower than when the procedures are all copied in the individual classes. Why is this?
Thanks