zoukankan      html  css  js  c++  java
  • 使用threading模块创建线程

    #_author:来童星
    #date:2019/12/17
    #使用threading模块创建线程
    import threading,time
    def process():
    for i in range(3):
    time.sleep(1)
    print('thread name is %s'%threading.current_thread().name)
    if __name__=='__main__':
    print('主线程开始')
    threads=[threading.Thread(target=process) for i in range(4)]# 创建4个线程存入列表
    for t in threads:
    t.start()
    for t in threads:
    t.join()
    print('主线程结束')
    运行结果:
    主线程开始
    thread name is Thread-4
    thread name is Thread-2
    thread name is Thread-1
    thread name is Thread-3
    thread name is Thread-1
    thread name is Thread-4
    thread name is Thread-3
    thread name is Thread-2
    thread name is Thread-3
    thread name is Thread-1
    thread name is Thread-4
    thread name is Thread-2
    主线程结束
  • 相关阅读:
    Beta 第七天
    Beta 第六天
    Beta 第五天
    Beta 第四天
    Beta 第三天
    Beta 第二天
    Beta 凡事预则立
    Beta 第一天
    Beta 集合
    打造专属测试平台5-使用Docker部署MySQL数据库
  • 原文地址:https://www.cnblogs.com/startl/p/12054484.html
Copyright © 2011-2022 走看看