Posted in Python onMay 06, 2014
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个线程是交替的执行的
python创建线程示例
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@