Ellen-琳子的博客多进程共享全局变量共享全局变量不适用于多进程编程 import multiprocessing a = 1 def demo1(): global a a += 1 def demo2(): # 进程是不共享全局变量的 线程是共享 print(a) # 1 if __name__ == '__...
拯救世界南如意的博客1、验证多线程是否共享全局变量 import threading import time #1.定义一个全局变量 g_num = 100 #2.定义2个函数,用他们来充当线程要执行的代码 def task1(): global g_num for i in range(3): g_num += 1 print(...