本文整理汇总了Python中multiprocessing.Process.procID方法的典型用法代码示例。如果您正苦于以下问题:Python Process.procID方法的具体用法?Python Process.procID怎么用?Python Process.procID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.Process
的用法示例。
在下文中一共展示了Process.procID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getSymbolDataToFileInParallel
# 需要导入模块: from multiprocessing import Process [as 别名]
# 或者: from multiprocessing.Process import procID [as 别名]
def getSymbolDataToFileInParallel(self, symbolArray, outFileArray, errorFile, numProcesses, numThreads):
"""
getSymbolDataToFileInParallel() : Using a linear extractor, launches multiple threads to extract data in parallel
Parameters are:
symbolArray: An array of symbols to download
outFileArray: An array of filenames (with path) where symbol data is to be saved
errorFile: An error file where any and all runtime errors are captured.
numThreads: An integer value between 1-32 of the number of threads to launch in parallel
"""
if (numProcesses > settings.MAX_PROCESSES):
numThreads = settings.MAX_PROCESSES
if (numThreads > settings.MAX_THREADS):
numThreads = settings.MAX_THREADS
if (len(symbolArray) < 1 or len(outFileArray) < 1 or len(symbolArray) != len(outFileArray)) :
raise Exception("Incorrect size of symbol or outputfile arrays")
print "Total symbols to download are : "+str(len(symbolArray))+'\n'
sliceSize = len(symbolArray)/numProcesses if len(symbolArray)%numProcesses == 0 else len(symbolArray)/(numProcesses-1)
myprocs = []
for x in range(numProcesses):
procName = "Process"+str(x)
start = sliceSize * x
if (x==numProcesses-1 and len(symbolArray)%numProcesses != 0):
print "Last Process will go with a length of : ",len(symbolArray)%(numProcesses-1)," instead of the sliceSize of ",sliceSize, "\n"
end = start + len(symbolArray)%(numProcesses-1) - 1
else:
end = start + sliceSize -1
ppr = ParallelProcessRunner(self.LinearExtractor)
pr = Process(target= ppr.launchThreadsForProcess, args=(symbolArray, outFileArray, errorFile+"_"+str(x), x, numThreads, start, end))
pr.procID = x
print "Launching Process number "+str(x) + "from "+str(start)+" to "+str(end)+'\n'
myprocs.append(pr)
for i in myprocs:
i.start()
""" Awaiting the threads to complete execution """
for i in myprocs:
i.join()
try:
final_error = open(errorFile, "w")
for i in myprocs:
err = open(errorFile+"_"+str(i.procID), "r")
final_error.write(err.read())
except:
print "Error writing output to the final error file \n"