新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythonthreading模塊的常用方法
說明

1、threading.curentthread():返回當(dāng)前線程變量。
2、threading.enumerate():返回包含正在運(yùn)行的線程的list。指線程啟動(dòng)后和結(jié)束前不包括啟動(dòng)前和結(jié)束后的線程。
threading.activeCount():與len(threading.enumerate()有相同的結(jié)果。
實(shí)例
"""
python threading模塊的常用方法
"""
import time
import threading
def test1():
print('------test1-------')
time.sleep(3)
def test2():
print('------test2-------')
time.sleep(3)
def main():
t1 = threading.Thread(target=test1)
t2 = threading.Thread(target=test2)
t1.start()
t2.start()
print('activeCount: %d' % threading.activeCount())
print(threading.enumerate())
while threading.activeCount() != 1:
time.sleep(1)
print(threading.enumerate())
print(threading.enumerate())
if __name__ == '__main__':
main()以上就是Python threading模塊的常用方法,希望對(duì)大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)Python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
文章名稱:創(chuàng)新互聯(lián)Python教程:Pythonthreading模塊的常用方法
文章出自:http://m.5511xx.com/article/djpggoo.html


咨詢
建站咨詢
