Distributed Initialization

Hi there,
can someone clarify at which point the distributed environment is exactly initialized and killed?

The use case would be if i have a script like the following:

# ... module and trainer init

trainer.fit(lightning_module, datamodule=data_module)
trainer.test(lightning_module, datamodule=data_module)

Could i utilize the trainer.is_global_zero property before or after calling .fit / .test to make some api calls, logging to console, local directory creation etc? Or is this property only accessible during the lightning execution pipeline via hooks or callbacks?

Regards
David