本文整理汇总了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...')