Determining if an Engine is running SGTK

I’m running an event driven script that (among other things) publishes media to ShotGrid.
I set up an Engine using this code:

mgr = sgtk.bootstrap.ToolkitManager(sg_user=user)

mgr.plugin_id = “stuff”
mgr.pipeline_configuration = ‘otherstuff’

engine = mgr.bootstrap_engine(“tk-shell”, entity=proj_hash)

This works as expected. However, the above code cannot be run until the event has actually happened and returned the values necessary to build proj_hash.
Once the event has occurred, however, the process may be called multiple times. When called again it throws an exception because it tries to launch a new Engine when one is already running.
I tried checking the condition of the engine using

engine = sgtk.platform.current_engine()

But this returns “None” in all cases (and I’m at a loss as to why)

Any suggestions, ideas, or solutions?

Hi @clint.thorne !

I was once in the same position as you and I found this workaround:

engine = mgr.bootstrap_engine(engine_name, entity=context_entity)
# We need to set the current engine for toolkit so we can retrieve it later with
# `tank.platform.current_engine()`.

So after you bootstrap you need to basically register the engine to sgtk in order to retrieve it later.

Hope that helps!


1 Like

Thank you! This was exactly what I needed.
just a quick addendum:
if I’m reading the documentation correctly, “tank” has been deprecated. The actual command I used was


But in any case, once again, thank you very much. I had been beating my head against that one for a while.

1 Like