python通过thread实现异步处理

import threading
import time
g_nums = [1,2]
 
def test1(temp):
    temp.append(33)
    print("-----in test1 temp=%s-----"% str(temp))
 
def test2(temp):
    print("-----in test2 temp=%s-----"% str(temp))
 
def main():
 
    t1 = threading.Thread(target=test1,args=(g_nums,))  # 加上要传递的参数,元组类型
    t2 = threading.Thread(target=test2, args=(g_nums,))  # args 元组类型
 
    t1.start()
    time.sleep(1)
 
    t2.start()
    time.sleep(1)
 
    print("-----in main temp=%s-----"% str(g_nums))
 
if __name__ == '__main__':
    main()

————————————————
版权声明:本文为CSDN博主「还是那个同伟伟」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wei18791957243/java/article/details/83995823

原文地址:https://www.cnblogs.com/hupingzhi/p/12739456.html