当前位置: 首页 > 工具软件 > Tomorrow > 使用案例 >

python tomorrow多线程应用

乐正育
2023-12-01
from tomorrow import threads
import os
import time
import requests

@threads(5)
def test(picpath):
    url = r'http://xxxxxxx:8000/plateTest/'
    #执行post请求
    myfile = {"picfile":open(picpath,'rb')}
    r = requests.post(url=url,files=myfile)

    r.encoding = 'utf-8'
    #打印返回结果
    info = r.json()
    print(info)

if __name__ == "__main__":
    dirpath = r'C:/Users/zc/Pictures/plate/'
    pics = [dirpath+i for i in os.listdir(dirpath)]
    t1 = time.time()
    for picpath in pics:
        test(picpath)
    print(time.time()-t1)
 类似资料: