다중 프로세스 실행(프로세스 수 제한)

12310 단어 python3
다중 프로세스 실행(프로세스 수 제한)
from ctypes import *
import os
import multiprocessing
import time, datetime
import multiprocessing as np

def testdll(wide,tele):
    dll = CDLL(os.getcwd()+"/"+"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(wide, 'utf-8'))  #    100       STR
    tele1 = (c_char * 300)(*bytes(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)  #     
    return {
        "    ":pchar,
        "  ":T
    }

def diclist(wide,tele):
    diclist = []
    n=1
    for i in os.listdir(wide):
        widepath = os.path.join(wide, i)
        for i1 in os.listdir(tele):
            telepath = os.path.join(tele, i1)
            dic = {
                "ID":n,
                "wide": widepath,
                "tele": telepath
            }
            diclist.append(dic)
            n=n+1
    return diclist

def test_xxx(wide,tele,c):
    print(c,testdll(wide,tele))

def main2():
    pool = multiprocessing.Pool(processes=4)
    for i in range(len(diclist(wide,tele))):
        path = diclist(wide, tele)[i]
        pool.apply_async(func=test_xxx, args=(path["wide"],path["tele"],i+1))
    pool.close()
    pool.join()  #  join       close,    

if __name__ == "__main__":
    wide = r"D:\Python\python3\Ceramic\release \test"
    tele = r"D:\Python\python3\Ceramic\release \test"


    T1 = datetime.datetime.now()
    print(T1)
    main2()
    T2 = datetime.datetime.now()
    print(T2)
    print(round((T2 - T1).total_seconds(), 3))


좋은 웹페이지 즐겨찾기