Cleanup FunctionsΒΆ

The photons_app object on the collector has an array of functions called cleaners.

Add an async function to this array to include it when Photons shuts down.

For example:

from photons_app.actions import an_action

async def run_the_thing(collector, target, **kwargs):
    thing = start_my_thing()

    async def shutdown_the_thing():
        await thing.shutdown()



if __name__ == "__main__":
    __import__("photons_core").run("lan:run_the_thing {@:1:}")

This is useful if there are many items to setup as it avoids the complexity of nested context managers or try..finally code blocks.