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

1、threading.curentthread():返回當前線程變量。
2、threading.enumerate():返回包含正在運行的線程的list。指線程啟動后和結束前不包括啟動前和結束后的線程。
threading.activeCount():與len(threading.enumerate()有相同的結果。
實例
"""
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模塊的常用方法,希望對大家有所幫助。更多Python學習指路:創(chuàng)新互聯Python教程
本文教程操作環(huán)境:windows7系統、Python 3.9.1,DELL G3電腦。
網站題目:創(chuàng)新互聯Python教程:Pythonthreading模塊的常用方法
文章源于:http://m.fisionsoft.com.cn/article/djpggoo.html


咨詢
建站咨詢
