本文整理汇总了Python中threading.Thread.oarsublock方法的典型用法代码示例。如果您正苦于以下问题:Python Thread.oarsublock方法的具体用法?Python Thread.oarsublock怎么用?Python Thread.oarsublock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类threading.Thread
的用法示例。
在下文中一共展示了Thread.oarsublock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import oarsublock [as 别名]
def run(self):
num_total_workers = 0
sites_clusters_threads = {} # dict: keys = sites, values =
# dict: keys = clusters, values =
# list: threads
try:
while True:
t = Timer()
clusters_to_submit = set()
for clusterspec in self.get_clusters():
cluster, _, site = clusterspec.partition(".")
if site == "":
site = get_cluster_site(cluster)
clusters_to_submit.add((cluster, site))
for site in sites_clusters_threads.keys():
for cluster in sites_clusters_threads[site].keys():
sites_clusters_threads[site][cluster] = [
th
for th in sites_clusters_threads[site][cluster]
if th.is_alive() ]
if len(sites_clusters_threads[site][cluster]) == 0:
del sites_clusters_threads[site][cluster]
if len(sites_clusters_threads[site]) == 0:
del sites_clusters_threads[site]
all_involved_sites = set(sites_clusters_threads.keys())
all_involved_sites.update([ s for (c, s) in clusters_to_submit ])
no_submissions = True
for site in all_involved_sites:
all_involved_clusters = set()
if sites_clusters_threads.has_key(site):
all_involved_clusters.update(sites_clusters_threads[site].keys())
all_involved_clusters.update([ c for (c, s) in clusters_to_submit if s == site ])
for cluster in all_involved_clusters:
num_workers = 0
num_waiting = 0
if sites_clusters_threads.has_key(site) and sites_clusters_threads[site].has_key(cluster):
num_workers = len(sites_clusters_threads[site][cluster])
num_waiting = len([
th
for th in sites_clusters_threads[site][cluster]
if th.waiting ])
num_max_new_workers = min(self.options.max_workers - num_workers,
self.options.max_waiting - num_waiting)
logger.trace(
"rescheduling on cluster %[email protected]%s: num_workers = %s / num_waiting = %s / num_max_new_workers = %s" %
(cluster, site, num_workers, num_waiting, num_max_new_workers))
if num_max_new_workers > 0:
for worker_index in range(0, num_max_new_workers):
jobdata = self.get_job(cluster)
if not jobdata:
break
no_submissions = False
logger.detail(
"spawning worker %i on %[email protected]%s" % (
num_total_workers,
cluster, site))
(oarsubmission, data) = jobdata
th = Thread(target = self.worker_start,
args = (cluster, site,
oarsubmission, data,
num_total_workers,))
th.waiting = True
th.daemon = True
th.oarsublock = Lock()
th.willterminate = False
th.start()
num_total_workers += 1
if not sites_clusters_threads.has_key(site):
sites_clusters_threads[site] = {}
if not sites_clusters_threads[site].has_key(cluster):
sites_clusters_threads[site][cluster] = []
sites_clusters_threads[site][cluster].append(th)
if no_submissions and len(sites_clusters_threads) == 0:
break
sleep(self.options.schedule_delay)
logger.detail("no more combinations to explore. exit schedule loop")
finally:
for site in sites_clusters_threads.keys():
for cluster in sites_clusters_threads[site].keys():
for th in sites_clusters_threads[site][cluster]:
with th.oarsublock:
th.willterminate = True
if th.jobid:
logger.detail("cleaning: delete job %i of worker #%i on %s" % (
th.jobid, th.worker_index, site))
oardel([(th.jobid, site)])
th.jobid = None