當前位置:首頁 » 編程語言 » pythonfor多線程

pythonfor多線程

發布時間: 2025-09-14 05:53:56

python如何並列運行兩個for循環

需要用到多線程
#!/usr/bin/python3

import _thread
import time

# 為線程定義一個函數
def print_time( threadName, delay):
....count = 0
....while count < 5:
........time.sleep(delay)
........count += 1
........print ("%s: %s" % ( threadName, time.ctime(time.time()) ))

# 創建兩個線程
try:
...._thread.start_new_thread( print_time, ("Thread-1", 2, ) )
...._thread.start_new_thread( print_time, ("Thread-2", 4, ) )
except:
....print ("Error: 無法啟動線程")

while 1:
....time.sleep(5)
....print('is main ')

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:583
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:877
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:572
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:758
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:674
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1001
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:245
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:104
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:796
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:702