源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

python创建线程示例

  • 时间:2020-05-12 09:02 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:python创建线程示例
[u]复制代码[/u] 代码如下:
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个线程是交替的执行的  
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部