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


Python Timer.record方法代码示例

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


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

示例1: __init__

# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import record [as 别名]
class ResourceManager:

	_frmk = None
	_pm = None
	_done = False
	_waiting = True

	_tracking = None
	_timer = None

	def __init__(self, frmk, pmanager ):
		self._frmk = frmk
		self._pm = pmanager
		self._done = False
		self._waiting = True

		self._tracking = {}
		self._timer = Timer(self.__class__.__name__)

		self.display( OUTPUT_VERBOSE, 'initialized' )

	def _nextTask(self):
		task = None
		pid = True
		while not pid == None:
			pid = self._pm.nextProc()
			if not pid == None:
				task = self._pm.nextTask( pid )
				if isinstance( task, Task ):

					if not pid in self._tracking:
						self._tracking[pid] = { 'out':{}, 'workers':[], 'done':False, 'noderef':{} }

					self._tracking[pid]['out'][task.key] = task
					self._timer.start( task.key )

					self.display( OUTPUT_LOGIC, 'got next task from process manager' )
					break
				else:
					self.display( OUTPUT_DEBUG, 'got invalid task from process manager' )
					pid = None


		return task

	def returnTask(self, task):
		if isinstance( task, Task ):
			pid = task.pid
			if task.sender in self._frmk.workers:
				winfo = self._frmk.workers[task.sender]
				winfo['slots'] = winfo['slots'] + task.slots

				if winfo['slots'] > winfo['mslots']:
					winfo['slots'] = winfo['mslots']

				if pid in self._tracking and task.key in self._tracking[pid]['out']:
					self.display( OUTPUT_DEBUG, 'known task returned' )
					del self._tracking[pid]['out'][task.key]
					self._timer.stop( task.key )
					self._timer.record()

				if isinstance( task, ControlTask ):
					if isinstance( task, CleanupTask ):
						self.display( OUTPUT_DEBUG, 'cleanup task completed')
						if self._pm.delProc( pid ) == pid:
							if pid in self._tracking:
								del self._tracking[pid]
					elif isinstance( task, DeployTask ):
						self.display( OUTPUT_DEBUG, 'deploy task completed')

					elif isinstance( task, ShutdownTask ):
						self.display( OUTPUT_DEBUG, 'shutdown task completed' )
						self._done = True

					elif isinstance( task, KillTask ):
						self.display( OUTPUT_DEBUG, 'kill task completed' )

					else:
						self.display( OUTPUT_DEBUG, 'control task belongs to process %d' % pid )
						self._pm.returnTask( task )
				else:
					self.display( OUTPUT_LOGIC, 'task returned to process %d' % pid )
					self._pm.returnTask( task )
			else:
				self.display( OUTPUT_DEBUG, 'got task from unknown sender' )

	def ready(self):
		result = False

		if not self._done:
			if not self._pm.nextProc() == None:
				result = True

			if not self._pm.firstDoneProc() == None:
				result = True

		return result

	def done(self):
		return self._done
#.........这里部分代码省略.........
开发者ID:averigin,项目名称:STARS,代码行数:103,代码来源:resourcemanager.py


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