标签:main 进程间 pytho target def == 进程 range 全局变量
全局变量在进程中是无法共享的
import time import multiprocessing """ 可发现在进程间全局变量不能共享 """ g_num = 10 def work1(): global g_num for i in range(10): g_num += 1 print("---------work1--------",g_num) def work2(): global g_num print("----work2----",g_num) if __name__ == ‘__main__‘: process_work1 = multiprocessing.Process(target=work1) process_work2 = multiprocessing.Process(target=work2) process_work1.start() process_work2.start() time.sleep(3) print("main",g_num)
标签:main 进程间 pytho target def == 进程 range 全局变量
原文地址:https://www.cnblogs.com/liuxjie/p/11984884.html