多程序執行(限制程序數)

2021-10-01 16:10:40 字數 2191 閱讀 7913

多程序執行(限制程序數)

from ctypes import

*import os

import multiprocessing

import time, datetime

import multiprocessing as np

deftestdll

(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

defdiclist

(wide,tele)

: diclist =

n=1for i in os.listdir(wide)

: widepath = os.path.join(wide, i)

for i1 in os.listdir(tele)

: telepath = os.path.join(tele, i1)

dic =

n=n+

1return diclist

deftest_***

(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](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))

shell多程序執行

shell在linux中,是使用者和kernel溝通的橋梁,採用c編寫,既是一種命令語言,也是一種解釋型指令碼語言,我們常寫的ls,grep就是基本的shell命令。shell指令碼是將要執行的命令按一定順序寫成的乙個文字檔案,最近遇到乙個需求,要將一定數量的命令快速執行,而每次執行都需要一定的時間...

多程序 多程序queue

多程序 import multiprocessing import threading import time defthread run print threading.get ident defrun name time.sleep 2 print hello name t threading....

linux程序數限制

rhel6裡面的程序數限制 為了防止fork bomb的出現,rhel6對普通使用者的程序數進行了限制,限制檔案為 etc security limits.d 90 nproc.conf 該檔案的內容為 default limit for number of user s processes to ...