from threading import Thread
import time
num=0
def work1():
time.sleep(1)
print("线程一%d"%num)
defwork2():
globalnum #在函数内部修改全局变量要加global声明
num+=1
print("线程二%d"%num)
t=Thread(target=work1)
t1=Thread(target=work2)
t.start()
t1.start()
from threading import Thread
import time
num=0
def work1():
time.sleep(1)
print("线程一%d"%num)
defwork2():
globalnum #在函数内部修改全局变量要加global声明
num+=1
print("线程二%d"%num)
t=Thread(target=work1)
t1=Thread(target=work2)
t.start()
t1.start()
本文标题:多线程修改全局变量
本文链接:https://www.haomeiwen.com/subject/mhzdvftx.html
网友评论