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


Python FileDict.hasKey方法代码示例

本文整理汇总了Python中FileDict.FileDict.hasKey方法的典型用法代码示例。如果您正苦于以下问题:Python FileDict.hasKey方法的具体用法?Python FileDict.hasKey怎么用?Python FileDict.hasKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileDict.FileDict的用法示例。


在下文中一共展示了FileDict.hasKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fromDir

# 需要导入模块: from FileDict import FileDict [as 别名]
# 或者: from FileDict.FileDict import hasKey [as 别名]

#.........这里部分代码省略.........
	
	def submit(self):
		# don't submit the same job twice
		assert self.submittedAt() is None
		assert self.jid() is None
		assert self.prepared
		qsubScript = self.qsubScript()
		self.metaOpt.setValue('submitted', timestamp())
		self.metaOpt.flush()
		self.javaOpt.flush()
		self.qsubOpt.flush()
		r = subprocess.check_output("qsub -N %s %s" % (self.name, qsubScript), shell=True)
		jid = int(r.split()[2])
		self.metaOpt.setValue('jid', jid, flush=True)
		print "submitted job \"%s\" (%d)" % (self.name, jid)

	def submittedAt(self):
		s = self.metaOpt.getValue('submitted')
		if s: return parsetime(s)
		else: return None

	def jid(self):
		s = self.metaOpt.getValue('jid')
		if s: return int(s)
		else: return None
	
	def failed(self):
		if self.recentlySubmitted():
			return False
		f = self.newestLog()
		if not f:
			print 'there is no log file, assuming it failed!'
		else:
			return self.f_hasFailed(f)

	def recentlySubmitted(self):
		'''
		give qsub some time to get its stuff together...
		for the first 5 seconds after submitting, just assume the
		job is running normally
		'''
		assert self.submittedAt() is not None
		return time.time() - self.submittedAt() < 10.0

	def isFinished(self):
		if self.recentlySubmitted() or self.isRunning():
			return False
		self.metaOpt.load()
		return self.metaOpt.hasKey('finished')

	def isRunning(self):
		if self.recentlySubmitted():
			return True
		assert self.jid() is not None
		assert type(self.jid()) is int
		running = Job.jobsRunning()
		return self.jid() in running

	def wait(self, timeout=48*60*60, secsBetweenPolls=30, exceptionOnTimeout=False):
		assert self.jid() is not None
		assert type(self.jid()) is int
		total = 0
		while total < timeout and self.isRunning():
			total += secsBetweenPolls
			time.sleep(secsBetweenPolls)
		if exceptionOnTimeout and total >= timeout:
			raise Exception("waited for %d seconds and job is not done!" % (total))
		else:
			print "waited %d seconds, but %d is done!" % (total, self.jid())

	def kill(self):
		if not self.isRunning():
			raise Exception('jid is none, job is not live')
		assert self.jid() is not None
		assert type(self.jid()) is int
		os.system("qdel %d" % (self.jid()))

	def pause(self):
		if not self.isRunning():
			raise Exception('jid is none, job is not live')
		assert self.jid() is not None
		assert type(self.jid()) is int
		os.system("qalter -u %d" % (self.jid()))

	def unpause(self):
		if not self.isRunning():
			raise Exception('jid is none, job is not live')
		assert self.jid() is not None
		assert type(self.jid()) is int
		os.system("qalter -U %d" % (self.jid()))

	def logs(self):
		assert self.logDir is not None and os.path.isdir(self.logDir)
		return [os.path.join(self.logDir, x) for x in os.listdir(self.logDir)]
	
	def newestLog(self):
		l = self.logs()
		if len(l) == 0:
			raise Exception('there are no logs!')
		return l[-1]
开发者ID:twolfe18,项目名称:twpt,代码行数:104,代码来源:tsub.py


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