通过本文主要向大家介绍了python示例程序,python简单代码示例,python代码示例,python序列乘法示例,python示例等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
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()
</div>
从输出结果可以看到,3个线程是交替的执行的
</div>

