In multi-threading, locking is required for operations that share data in common.
However, for local variables , each thread is independent of each other.
If the thread t want to F1 the function in the local variable V1 to the function F2, F2 again want to put this variable to F3, a layer of a layer of the more cumbersome to pass.
Name the object returned by Python's threading.local () tl, place the TL at the Global location, and bind the properties to the TL in each function.
TL can be regarded as a dictionary, the key value is the thread ID, value is a dictionary , value represents the dictionary contains our bound properties.
The question here is, if the thread T1 knows the ID of the thread T2, wouldn't it be possible to modify the thread T2 data in threads T1? This involves a thread-isolation problem.
The actual threading.local () dealt with the situation, and the principle was later studied.
This way, when multithreaded execution, by using threading.local (), for each thread, you can easily access the data of their own thread anywhere ,
Each thread is isolated from each other and does not interfere with each other.
The threadlocal in Python