1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Process level variable in celery

Discussão em 'Python' iniciado por Stack, Maio 7, 2025.

  1. Stack

    Stack Membro Participativo

    I have a setup where I use celery with concurrency. There is a variable defined in the module for db connection pooling. The problem is that celery's concurrency makes each process access that variable. Is there any way to make a process-level variable?

    # this dict available for all processes of celery worker
    # however my goal is to cache connection on process level
    db_connection_pool = {}

    def get_connection(some_id):
    if conn := db_connection_pool.get(some_id):
    return conn
    conn, some_id = create_connection()
    db_connection_pool[some_id] = conn
    return conn

    Continue reading...

Compartilhe esta Página