<p>我知道在python中使用threadlocal是可能的,但是由于某些原因,我无法找到实现这一点的确切语法。我有下面的示例代码来测试这一点,但这不起作用-</p>
<p>模块1.py</p>
<pre><code>import threading
def print_value():
local = threading.local() // what should I put here? this is actually creating a new thread local instead of returning a thread local created in main() method of module2.
print local.name;
</code></pre>
<p>模数2.py</p>
^{pr2}$
<p>共享数据应该只对调用这些函数的线程可用,而不是对系统中的所有线程可用。一个例子是web应用程序中的请求id。在</p>