Is how I did it for napari-imagej. But I think this won't work for your use case because your code needs to continue on the main thread, no? So then we are looking at another option, which I haven't coded yet: pass the rest of your code to a new callback function that PyImageJ calls after doing ij.ui().showUI() in GUI mode.
This means using: [] using pyimagej not in interactive mode [] write bash scripts for conda constructor
Avoiding pyimagej interactive is the crucial part. Directions given by Curtis: