@多线程共享全局变量(带args参数)
1 import threading
2 import time
3
4 g_num=[11,22]
5
6 def test1(temp):
7 temp.append(100)
8 print("---test1---%s"%str(temp))
9
10 def test2(temp):
11 print("---test2---%s"%str(temp))
12
13 def main():
14 t1=threading.Thread(target=test1,args=(g_num,))
15 t2=threading.Thread(target=test2,args=(g_num,))
16 t1.start()
17 time.sleep(1)
18 t2.start()
19 time.sleep(1)
20 print(g_num)
21
22 if __name__=="__main__":
23 main()