Skip to content

Lightrun with Celery


Celery is an infrastructure that allows you to run parallel tasks. To do that, Celery opens a different process for each task and syncronize them. In order to use Lightrun with Celery we need Lightrun’s agent to run on each of Celery’s processes.


Celery offers a way to run a designated code on each of the processes as they are spawned. Lightrun uses this ability to integrate its agent on the running process.


On the .py file where Celery is initiated (where there is a call to Celery(), usually the following code should be inserted

 from celery.signals import worker_process_init

 def long_init_function(*args, **kwargs):
         import lightrun
         lightrun.enable(company="<COMPANY_NAME>" , company_key="<COMPANY_SECRET>")
     except ImportError as e:
         print("Error importing Lightrun: ", e)

Important! you might need to provide lightrun_extra_class_path to make sure Lightrun is able to index all the functions.

Last update: May 18, 2022