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


Python Backend.worker_for_name方法代码示例

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


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

示例1: Worker

# 需要导入模块: from backend import Backend [as 别名]
# 或者: from backend.Backend import worker_for_name [as 别名]
class Worker(Process):

	def __init__(self, backendUrl):
		super(Worker, self).__init__()
		self.name = socket.gethostname()
		self.backend = Backend(backendUrl)
		worker = self.backend.worker_for_name(self.name)
		if '_id' in worker:
			self.workerId = worker['_id']
			self.backend.workerId = self.workerId
		else:
			raise Exception('Worker has no id!!!!')
		self._stop = Event()

	def stop(self):
		self._stop.set()

	def stopped(self):
		return self._stop.is_set()

	def run(self):
 		deviceLoops = {}

		while not self.stopped():
			devices = iDevice.devices()
			currDeviceUDIDs = []
			# search for new devices
			for device in devices:
				currDeviceUDIDs.append(device.udid)
				if device.udid not in deviceLoops:
					dLoop = DeviceLoop(device, self.backend)
					dLoop.start()
					deviceLoops[device.udid] = dLoop
					logger.info('Started device loop for %s', device.udid)

			# cleanup finished processes
			for udid in deviceLoops.keys():
				if udid not in currDeviceUDIDs:
					dLoop = deviceLoops[udid]
					if dLoop.is_alive():
						dLoop.stop()
						logger.info('Waiting for DeviceLoop to stop... (%s)', udid)
						dLoop.join(10)
						if dLoop.is_alive():
							logger.info('... loop has not yet stopped. Terminating the loop now.  (%s)', udid)
							dLoop.terminate()
					deviceLoops.pop(udid)
					logger.info('Device loop finished: %s', udid)
			time.sleep(5)

		logger.info('runloop is shutting down. Stoping all client processes gracefully')
		for udid, process in deviceLoops:
			logger.info('joining device loop for device %s', udid)
			process.join()
		logger.info('Worker has finished working...')
开发者ID:L45eMy,项目名称:Worker,代码行数:57,代码来源:worker.py


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