a=100
b=100
#多线程可以共享全局变量
from multiprocessing import Process
from threading import Thread
def work1():
global a,b
for i in range(3):
a+=1
b+=1
print(‘a=%d,b=%d’%(a,b))
def work2():
global a,b
for i in range(3):
a+=1
b+=1
print(‘a=%d,b=%d’ % (a, b))
ifname== ‘main’:
# t1=Thread(target=work1)
# t2 = Thread(target=work2)
# t1.start()
# t2.start()
p1=Process(target=work1)
p2 = Process(target=work2)
p1.start()
p2.start()