from celery import Celery from celery.signals import worker_process_init from telethon import TelegramClient app = Celery('tasks', broker='redis://localhost:6379/2', backend='redis://localhost:6379/3') api_id = 123 # set your api id api_hash = 'qwe' # set your api hash client = None # init one client per worker process @worker_process_init.connect def setup_connections(**kwargs): global client client = TelegramClient('session_name', api_id, api_hash) client.start() @app.task def test(): global client return client.get_me().id