[英]Threads are not alive using python multithreading?
我正在使用python的多線程模塊,但是代碼有時無法正常工作。 我打印了活動線程的計數,發現有時啟動的線程不是活動的。 這是代碼:
def do_stuff(q,obj):
while not q.empty():
item=q.get()
print item
q.task_done()
for i in range(num_thread):
worker=threading.Thread(target=do_stuff,args=(q,Files,))
worker.setDaemon(True)
worker.start()
print worker.is_alive()
print threading.active_count()
print threading.enumerate()
對於is_alive()函數,我得到了False,並且活動線程列表中只有一個線程(主線程)。
我在這里做錯了什么?
非常感謝!
您的線程還沒有時間開始。
根據文檔
is_alive()
isAlive()
返回線程是否處於活動狀態。
該方法在
run()
方法開始之前直到run()
方法終止之后才返回True
。 模塊函數enumerate()
返回所有活動線程的列表。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.