Has the idea of using contextvars to hold a mutable container been tried? In a process that has many initialization parameters. Some are set at startup from configparser however others are changed only after runtime based on various factors. For clarity of code and to avoid issues with threads setting different runtime vars we created a singleton class/object to hold all dynamically modified runtime parameters. Basically a key value list similar to how configparser holds data. With the option to lock it after all parameters are set. In order to share the parameters across the entire process and to allow each thread access to the general parameters and the ability to set thread specific parameters. Has anyone implemented something similar? In order to avoid threading conflicts the option to use contextvars to hold the runtime variable class was raised. However we are having trouble figuring out what the proper way to implement using it would be - or if it’s even possible. Should the runtime parameters class be set once as a singleton on startup and the contextvars be included in the class? With contextvars holding a dictionary of key-values? Or create contextvars separately and have the runtime class access it - which would mean each file would need two imports one for contextvars and one for the class? Is there a better way of managing this scenario without using contextvars? Continue reading...