Python 通过ThreadPoolExecutor调用的函数能否正确重置实例属性?
我正在使用Python 通过ThreadPoolExecutor调用的函数能否正确重置实例属性?,python,multithreading,threadpoolexecutor,Python,Multithreading,Threadpoolexecutor,我正在使用ThreadPoolExecutor.map()函数调用类中的方法(位于不同的文件中,我认为这并不重要)。方法调用在类的同一实例上 我的问题是:如果该方法使用类变量(在该方法完成后重置为默认值),是否仍有任何值被ThreadPoolExecutormap函数错误映射 模板代码如下: import class2 from classFile2 from concurrent.futures import ThreadPoolExecutor c2 = class2() def eval
ThreadPoolExecutor.map()
函数调用类中的方法(位于不同的文件中,我认为这并不重要)。方法调用在类的同一实例上
我的问题是:如果该方法使用类变量(在该方法完成后重置为默认值),是否仍有任何值被ThreadPoolExecutor
map函数错误映射
模板代码如下:
import class2 from classFile2
from concurrent.futures import ThreadPoolExecutor
c2 = class2()
def eval(values):
with ThreadPoolExecutor() as exe:
iterator = exe.map(c2.method, values, timeout=0.5, chunksize=1)
如果
c2.method
使用重置的类变量,那么iterator
和c2.method(value)之间是否会有任何差异。如果r1=c2.method(v1)
,r2=c2.method(v2)
和result=[r1,r2]
,那么这是否等于pool.map(c2,method,values,…)
,在这种情况下,不等于。问题的出现是因为类的单个实例被多个线程并发使用。