當前位置:首頁 » 編程語言 » 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 ')

熱點內容
sqlsaserver 發布:2025-09-14 07:44:42 瀏覽:960
pythonif寫一行 發布:2025-09-14 07:41:39 瀏覽:993
lua存儲數據 發布:2025-09-14 07:33:05 瀏覽:111
教你如何選配置車 發布:2025-09-14 07:32:21 瀏覽:417
行李箱自帶的密碼是多少 發布:2025-09-14 07:27:40 瀏覽:278
ps2020版本怎麼調整存儲盤 發布:2025-09-14 07:20:28 瀏覽:860
奧迪a6哪個配置最保值 發布:2025-09-14 07:11:53 瀏覽:986
android查看文件 發布:2025-09-14 07:00:37 瀏覽:291
carlyle壓縮機 發布:2025-09-14 06:16:51 瀏覽:978
支持ftp免費空間 發布:2025-09-14 06:05:16 瀏覽:208