码迷,mamicode.com
首页 > 编程语言 > 详细

Python3 多线程 学习 threading

时间:2016-06-08 18:48:02      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

#-*- coding:utf-8 --*-
#多线程测试 

import time
import datetime
import threading

def worker():

    print("未用多线程")
    time.sleep(1)

    return

def worker2():
    print("使用多线程")
    time.sleep(1)
    return

if __name__ == "__main__"    :
    d1 = datetime.datetime.now()    
    for i in range(5):
        worker()
    d2 = datetime.datetime.now()
    print(d2-d1)

    d1 = datetime.datetime.now()    
    for j in range(5):
        t = threading.Thread(target = worker2)
        t.start()
    d2 = datetime.datetime.now()
    print(d2 - d1)
    print("current has %d threads" % (threading.activeCount() - 1))

 

Python3 多线程 学习 threading

标签:

原文地址:http://www.cnblogs.com/lrzy/p/5570719.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!