'Python class variable usage across thread have different value

I'm getting confused about class variable access through multi-thread. I'm in a django application and I initialize a class at server startups to inject some configuration. Then on user requests I call some method on that class but the config is None.

class SharedService:
    _queue_name = None

    @staticmethod
    def config(queue_name=None):
        if queue_name:
            SharedService._queue_name = queue_name
        print(SharedService._queue_name)    # this print the "alert"

    @staticmethod
    def send_message(data):
        print(SharedService._queue_name)    # this print None should print "alert"

if usefull in the django settings class loaded at startup I do:

SharedService.config(queue_name="alert")

and in the user endpoint I just call:

SharedService.send_message("blabla")

I'm sure it did work previously, but we did update to python 3.10 and django 3.2 recently and might be related (or not!)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source