当前位置: 首页>>代码示例>>Python>>正文


Python Process.procID方法代码示例

本文整理汇总了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"
开发者ID:nitingoel,项目名称:Stocks-Project,代码行数:51,代码来源:extractors.py


注:本文中的multiprocessing.Process.procID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。