There is a single starting point for each thread where all dynamically set parameters are initialized. However some of the parameters are the same across the entire process for all threads and other parameters are thread specific. Ideally it would be best if in the process later there is no need to know which parameters were set by which part and that they could all be accessed in the same way. Example: general settings: groupname = abc, base_lookback = 5 thread specific settings: final_lookback = 8 Ideally access to groupname, base_lookback, final_lookback should be the same ctx.base_lookback or ctx.final_lookback should both work without the thread having to know if the parameters are thread specific. Having a new dictionary for each thread would mean that the two parts of the data are separate or we would have to copy the general data into each thread specific dictionary.
From what I understood of extracontext it essentially does what we were trying to do - set up a contextvars which allows multiple variables. If we instantiate extracontext one time so that it acts as a singleton.
context.py
ctx = ContextLocal()
file1.py
from context import ctx
file2.py
from context import ctx
We would then have the same contextlocal used throughout the process. It can be initialized at the beginning with all general parameters and then per thread with thread specific parameters and it would be thread and async safe. Am I understanding correctly?
We could then add a decorator around it to lock it also.