首页 > 编程语言 > 详细

多线程编程入门练习

时间:2019-04-02 13:32:20      阅读:125      评论:0      收藏:0      [点我收藏+]
import threading
import time


def thread_job1():

    for it in range(10):
        time.sleep(0.1)
    print(This is an added Thread1, number is %s % threading.current_thread())


def thread_job2():
    for it in range(10):
        time.sleep(0.1)
    print(This is an added Thread2, number is %s % threading.current_thread())


def main():

    thread1 = threading.Thread(target=thread_job1)
    thread1.start()
    thread2 = threading.Thread(target=thread_job2)
    thread2.start()
    print(threading.active_count()) #已激活线程数量
    print(threading.enumerate()) #已激活线程详细信息
    print(threading.current_thread()) #目前运行的线程


if __name__ == __main__:
    main()

 

多线程编程入门练习

原文:https://www.cnblogs.com/ACPIE-liusiqi/p/10641537.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!