Python多进程之间不共享全局变量
import multiprocessing gl_list=[] def add_list(): for i in range(3): gl_list.append(i) print("子进程的gl_list",gl_list) def read_list(): print(gl_list) # 多进程之间不共享全局变量 if __name__ == '__main__': add_process = multiprocessing.Process(target=add_list) read_process = multiprocessing.Process(target=read_list) add_process.start() add_process.join() #主进程等待add_process执行完毕再执行 read_process.start() print("主进程的gl_list",gl_list)