您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python创建线程示例

5b51 2022/1/14 8:17:54 python 字数 868 阅读 336 来源 www.jb51.cc/python

复制代码代码如下:importthreadingfromtimeimportsleep deftest_func(id):???foriinrange(0,5):???????sleep(1)???????prin

概述

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

 

总结

以上是编程之家为你收集整理的python创建线程示例全部内容,希望文章能够帮你解决python创建线程示例所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶