多线程执行(限制线程数)

多线程执行(限制线程数)


# -*- coding: utf-8 -*-
import threading
from ctypes import *
import queue,os
import time, datetime


class store(threading.Thread):
    def __init__(self, store, queue,wide,tele):
        threading.Thread.__init__(self)
        self.queue = queue
        self.store = store
        self.wide = wide
        self.tele = tele

    def testdll(self):
        dll = CDLL(r"D:\Python\python3\Ceramic\release版\SealDet_surf_ncc_V22_vs2017_akaze_release_dll.dll")  # 初始化dll,加载dll
        dll.SealDet_surf_ncc.argtypes = [POINTER(c_char), POINTER(c_char), c_int, c_float]  # 定义dll入参类型
        dll.SealDet_surf_ncc.restype = c_float  # 定义dll出参类型,不定义程序不知道类型会报错
        wide1 = (c_char * 300)(*bytes(self.wide, 'utf-8'))  # 把一组100个的字符定义为STR
        tele1 = (c_char * 300)(*bytes(self.tele, 'utf-8'))  # 把一组100个的字符定义为STR
        # cast(wide1, POINTER(c_char))
        # cast(tele1, POINTER(c_char))
        T1 = datetime.datetime.now()
        pchar = dll.SealDet_surf_ncc(wide1, tele1, 20, 0.1)
        T2 = datetime.datetime.now()
        T = round((T2 - T1).total_seconds(), 3)  # 检索耗时
        dic = {
            "匹配系数": pchar,
            "耗时": T
        }
        # print(dic)
        return dic


    def run(self):
        try:
           print( self.store,self.testdll())
        except Exception as e:
            print(e)
        finally:
            self.queue.get()
            self.queue.task_done()
def diclist(wides,teles):
    diclist = []
    n=1
    for i in os.listdir(wides):
        widepath = os.path.join(wides, i)
        for i1 in os.listdir(teles):
            telepath = os.path.join(teles, i1)
            dic = {
                "ID":n,
                "wide": widepath,
                "tele": telepath
            }
            diclist.append(dic)
            n=n+1
    return diclist
def main():
    q = queue.Queue(maxThreads)
    for s in range(len(diclist(wides,teles))):
        dic=diclist(wides, teles)[s]
        q.put(s)
        t = store(s, q,dic["wide"],dic["tele"])
        t.start()
    q.join()


if __name__ == '__main__':
    wides = r"D:\Python\python3\Ceramic\release版\test"
    teles = r"D:\Python\python3\Ceramic\release版\test"
    maxThreads = 4
    main()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值