I can’t say I’m an expert in developing for toolkit and I’m pretty sure I do many things wrong still, but I’ve hit the problems you describe.
When debugging the app in tk-desktop engine, I rely heavily on the file log. The console says it will switch to the file based logging at the point it starts loading toolkit apps:
2020-05-08 02:34:01,799 [ DEBUG] [PROXY] Project-level tk-desktop engine will now switch back to file based logging.
2020-05-08 02:34:01,819 [ DEBUG] [PROXY] Switching file based std logger from 'None' to 'C:\Users\<username>\AppData\Roaming\Shotgun\Logs\tk-desktop.log'.
I don’t know if it is possible to disable this “switching” but since this file containts an extreme amount of debug data, I wouldn’t even like that. It’s preferable for me to simply tail it when I need to.
Also, one method to ensure as much information as possible when app fails to load is to catch the error in init_app method of your Application class. tk-multi-starterapp shows how to load the app module and register command but I always enclose these two methods in try/except block and use traceback module just to be sure.
Here’s how it usually looks like in the apps I’ve created:
from sgtk.platform import Application
APP_NAME = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
The app entry point. This class is responsible for initializing and tearing down
the application, handle menu registration etc.
Called as the application is being initialized
# first, we use the special import_module command to access the app module
# that resides inside the python folder in the app. This is where the actual UI
# and business logic of the app is kept. By using the import_module command,
# toolkit's code reload mechanism will work properly.
self.app_payload = self.import_module("app")
except Exception as err:
self.log_warning("Could not import module!")
display_name = self.get_setting("display_name")
menu_caption = display_name
# register command
def menu_callback(): return self.app_payload.show_dialog(self)
# now register the command with the engine
except Exception as err:
self.log_warning("Could not register command!")
Additionally, I made a simple tool to restart the engine and reload everything (as I’ve figured that template.yml is not being reloaded by shotgun provided “Reload and Restart” command) and run on a click of a (automatically generated) button for every app:
This just saves me from writing the same restart code every time.
I’d love to hear other peoples experience though. Particularly on the topic of testing…