欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python創(chuàng)建線程示例

 更新時間:2014年05月06日 13:57:00   作者:  
這篇文章主要介紹了python創(chuàng)建線程示例,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

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()


從輸出結(jié)果可以看到,3個線程是交替的執(zhí)行的

 

相關(guān)文章

最新評論