本文整理汇总了Python中ThreadPool.ThreadPool.addWorkerThread方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.addWorkerThread方法的具体用法?Python ThreadPool.addWorkerThread怎么用?Python ThreadPool.addWorkerThread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThreadPool.ThreadPool
的用法示例。
在下文中一共展示了ThreadPool.addWorkerThread方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildGivenPackages
# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import addWorkerThread [as 别名]
def buildGivenPackages (self, listPackages):
returnVal=self.calculateParams(listPackages)
if not returnVal:
self.logger.error("Unable to set paramaters. Terminating the package manager.")
return False
statusEvent=threading.Event()
numWorkerThreads=self.calculatePossibleNumWorkerThreads()
if numWorkerThreads > 8:
numWorkerThreads = 8
if numWorkerThreads == 0:
return False
self.initializeScheduler(statusEvent)
self.initializeThreadPool(statusEvent)
i=0
while i < numWorkerThreads:
workerName="WorkerThread"+str(i)
ThreadPool.addWorkerThread(workerName)
ThreadPool.startWorkerThread(workerName)
i = i + 1
statusEvent.wait()
Scheduler.stopScheduling=True
self.logger.info("Waiting for all remaining worker threads")
listWorkerObjs=ThreadPool.getAllWorkerObjects()
for w in listWorkerObjs:
w.join()
setFailFlag=False
allPackagesBuilt=False
if Scheduler.isAnyPackagesFailedToBuild():
setFailFlag=True
if Scheduler.isAllPackagesBuilt():
allPackagesBuilt=True
if setFailFlag:
self.logger.error("Some of the packages failed:")
self.logger.error(Scheduler.listOfFailedPackages)
return False
if not setFailFlag:
if allPackagesBuilt:
self.logger.info("All packages built successfully")
else:
self.logger.error("Build stopped unexpectedly.Unknown error.")
return False
self.logger.info("Terminated")
return True
示例2: buildGivenPackages
# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import addWorkerThread [as 别名]
def buildGivenPackages (self, listPackages, buildThreads):
if constants.rpmCheck:
alreadyBuiltRPMS=self.readAlreadyAvailablePackages()
listPackages=list(set(listPackages)|(set(constants.listMakeCheckRPMPkgtoInstall)-set(alreadyBuiltRPMS)))
returnVal=self.calculateParams(listPackages)
if not returnVal:
self.logger.error("Unable to set paramaters. Terminating the package manager.")
raise Exception("Unable to set paramaters")
statusEvent=threading.Event()
self.initializeScheduler(statusEvent)
self.initializeThreadPool(statusEvent)
i=0
while i < buildThreads:
workerName="WorkerThread"+str(i)
ThreadPool.addWorkerThread(workerName)
ThreadPool.startWorkerThread(workerName)
i = i + 1
statusEvent.wait()
Scheduler.stopScheduling=True
self.logger.info("Waiting for all remaining worker threads")
listWorkerObjs=ThreadPool.getAllWorkerObjects()
for w in listWorkerObjs:
w.join()
setFailFlag=False
allPackagesBuilt=False
if Scheduler.isAnyPackagesFailedToBuild():
setFailFlag=True
if Scheduler.isAllPackagesBuilt():
allPackagesBuilt=True
if setFailFlag:
self.logger.error("Some of the packages failed:")
self.logger.error(Scheduler.listOfFailedPackages)
raise Exception("Failed during building package")
if not setFailFlag:
if allPackagesBuilt:
self.logger.info("All packages built successfully")
else:
self.logger.error("Build stopped unexpectedly.Unknown error.")
raise Exception("Unknown error")
self.logger.info("Terminated")
示例3: _buildGivenPackages
# 需要导入模块: from ThreadPool import ThreadPool [as 别名]
# 或者: from ThreadPool.ThreadPool import addWorkerThread [as 别名]
def _buildGivenPackages(self, listPackages, buildThreads):
# Extend listPackages from ["name1", "name2",..] to ["name1-vers1", "name2-vers2",..]
listPackageNamesAndVersions=set()
for pkg in listPackages:
base = SPECS.getData().getSpecName(pkg)
for version in SPECS.getData().getVersions(base):
listPackageNamesAndVersions.add(base+"-"+version)
returnVal = self._calculateParams(listPackageNamesAndVersions)
if not returnVal:
self.logger.error("Unable to set parameters. Terminating the package manager.")
raise Exception("Unable to set parameters")
statusEvent = threading.Event()
self._initializeScheduler(statusEvent)
self._initializeThreadPool(statusEvent)
for i in range(0, buildThreads):
workerName = "WorkerThread" + str(i)
ThreadPool.addWorkerThread(workerName)
ThreadPool.startWorkerThread(workerName)
statusEvent.wait()
Scheduler.stopScheduling = True
self.logger.debug("Waiting for all remaining worker threads")
ThreadPool.join_all()
setFailFlag = False
allPackagesBuilt = False
if Scheduler.isAnyPackagesFailedToBuild():
setFailFlag = True
if Scheduler.isAllPackagesBuilt():
allPackagesBuilt = True
if setFailFlag:
self.logger.error("Some of the packages failed:")
self.logger.error(Scheduler.listOfFailedPackages)
raise Exception("Failed during building package")
if not setFailFlag:
if allPackagesBuilt:
self.logger.debug("All packages built successfully")
else:
self.logger.error("Build stopped unexpectedly.Unknown error.")
raise Exception("Unknown error")