python创建线程示例

517次阅读  |  发布于5年以前

复制代码 代码如下:

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

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8