因为在Windows中,多处理需要放在__main__
以内,所以我发现我的全局变量没有传递给我的函数.
from multiprocessing import Pool, Value
def Proses(lines):
global xyz
try:
print(lines)
print(xyz)
except Exception as e:
print(e)
def counter_handler(args):
global counter
counter = args
def Dosomething():
a = [i for i in range(10)]
return a
if __name__ == '__main__':
# i want to share xyz variable
xyz = Dosomething()
threads = []
data = ["bjir", "bjir", "bjir"]
counter = Value('i', 0)
with Pool(1) as pool:
p = Pool(1, initializer=counter_handler, initargs=(counter,))
i = p.map_async(Proses, data, chunksize=1)
i.wait()
我已经找了几个小时了,但仍然没有任何线索,我想这可能是一个重复的队列,我知道它,但我仍然找不到任何答案.有没有办法把xyz
变量传递给我的函数?