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

python中多线程

时间:2020-02-25 20:28:23      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:time   alt   nbsp   div   start   second   range   get   inf   

import threading
import time
from datetime import datetime as dt


def say_hello(word):
    time.sleep(1)
    print(word)


pool = []
now = dt.now()
for x in range(10):
    t = threading.Thread(target=say_hello, args=(x,))
    t.start()
    pool.append(t)

for t in pool:
    t.join()
end = dt.now()
print(‘总时间:‘, (end - now).total_seconds())

技术图片

 

python中多线程

标签:time   alt   nbsp   div   start   second   range   get   inf   

原文地址:https://www.cnblogs.com/ldlx-mars/p/12363205.html

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