main.py
import multiprocessing.pool as Pool
from test import set_data, get_multiprocessing
if __name__ == '__main__':
data_list = ['data1', 'data2', 'data3']
set_data(data_list)
res = get_multiprocessing(2)
print(res)
test.py
import time
import multiprocessing
_t = None
def set_data(t):
time.sleep(1)
global _t
_t = t
def get_data(idx):
return _t[idx]
def get_multiprocessing(num_threads):
pool = multiprocessing.Pool(processes=num_threads)
res = pool.map(get_data, range(1))
pool.close()
pool.join()
return [r for r in res]
我想要等这个全局变量赋值之后再进行多进程,有什么办法吗?
向大佬们请教