python創(chuàng)建線程示例
更新時間:2014年05月06日 13:57:00 作者:
這篇文章主要介紹了python創(chuàng)建線程示例,需要的朋友可以參考下
復制代碼 代碼如下:
import threading
from time import sleep
def test_func(id):
for i in range(0,5):
sleep(1)
print('thread %d is running %d' % (id,i))
threads = []
for i in range(0,3):
t = threading.Thread(target=test_func, args=(i,))
threads.append(t)
for t in threads:
t.start()
for t in threads:
t.join()
從輸出結果可以看到,3個線程是交替的執(zhí)行的
相關文章
Python?matplotlib包和gif包生成gif動畫實戰(zhàn)對比
使用matplotlib生成gif動畫的方法相信大家應該都看到過,下面這篇文章主要給大家介紹了關于Python?matplotlib包和gif包生成gif動畫對比的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-05-05
Python3之外部文件調用Django程序操作model等文件實現方式
這篇文章主要介紹了Python3之外部文件調用Django程序操作model等文件實現方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04

