多线程编程入门练习

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

猜你喜欢

转载自www.cnblogs.com/ACPIE-liusiqi/p/10641537.html
今日推荐