标签:append getname 其他 coding AC join 主线程 UI ==
初试
# -*- coding:utf-8 -*- # Author:Brownyangyang import threading import time def sayhi(n): lock.acquire() ##加锁,只有我这个线程才可以解锁,其他线程无法修改值 global num num += 1 lock.release() ##解锁 lock = threading.Lock() ##实例化一把锁 num = 0 #if __name__ == ‘__main__‘: #start_time=time.time() item_liyan = [] for i in range(500): t = threading.Thread(target=sayhi,args=(i,)) #t.setDaemon(True) ##把当前线程设置成守护线程,主进程执行完不会等子进程 t.start() #t2.start() item_liyan.append(t) # for j in item_liyan: # j.join() ##join等待子线程运行完毕 print("number %s" %num) print(threading.current_thread()) ##打印主线程 #print(t1.getName()) #print(t2.getName())
标签:append getname 其他 coding AC join 主线程 UI ==
原文地址:https://www.cnblogs.com/brownyangyang/p/8901797.html