我正在使用多处理。我的CPU有四个核心,我将池的进程设置为2。
1)如果我同时运行同一程序(多次运行相同的时间),它将使用我的所有内核吗?是的,如果同时运行一个内核,那么如何设置总是免费的。
2)我在每个国家/地区分别运行没有问题,但是如果我在不同国家/地区同时运行上述文件,则该文件会在7-8小时后挂起
关于悬挂原因以及如何追踪悬挂原因的任何想法吗?
import time
from multiprocessing import Pool
from functools import partial
import os
class Test:
country = ''
def __init__(self, countryCode):
self.country = countryCode
def Mainfn_New(self):
#around 10-20 files
inputpath = "C:\\" + self.country + "\\Inputfiles"
dirlist = os.listdir(inputpath)
print(inputpath)
print(dirlist)
print("START Main")
pool = Pool(2)
func = partial(self.HugeProcess, inputpath)
results = pool.map(func, dirlist)
pool.close()
pool.join()
print("End Main")
def HugeProcess(self, inputpath, filename):
#Proces will take around 10-30 mins to complete the process
print("START HugeProcess ***" , filename)
#time.sleep(1)
print("END HugeProcess ***", filename)
if __name__ == '__main__':
print("Starting .........")
#country code MY
obj = Test('MY')
obj.Mainfn_New()