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


Python BaseManager.register方法代码示例

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


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

示例1: start

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
    def start(self):

        # 把派发作业队列和完成作业队列注册到网络上
        BaseManager.register(
            'get_dispatched_job_queue', callable=self.get_dispatched_job_queue)
        BaseManager.register(
            'get_finished_job_queue', callable=self.get_finished_job_queue)

        # 监听端口和启动服务
        manager = BaseManager(address=('0.0.0.0', 8888), authkey='jobs')
        manager.start()

        # 使用上面注册的方法获取队列
        dispatched_jobs = manager.get_dispatched_job_queue()
        finished_jobs = manager.get_finished_job_queue()

        # 这里一次派发10个作业,等到10个作业都运行完后,继续再派发10个作业
        job_id = 0
        while True:
            for i in range(0, 10):
                job_id = job_id + 1
                job = Job(job_id)
                print('Dispatch job: %s' % job.job_id)
                dispatched_jobs.put(job)

            while not dispatched_jobs.empty():
                job = finished_jobs.get(60)
                print('Finished Job: %s' % job.job_id)

        manager.shutdown()
开发者ID:AllenThePythonic,项目名称:DEV,代码行数:32,代码来源:master.py

示例2: start

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
    def start(self,skip=0):
        # 把派发作业队列和完成作业队列注册到网络上
        BaseManager.register('get_dispatched_job_queue', callable=self.get_dispatched_job_queue)
        BaseManager.register('get_finished_job_queue', callable=self.get_finished_job_queue)

        # 监听端口和启动服务
        manager = BaseManager(address=('0.0.0.0', rpc_port), authkey=authkey)
        manager.start()

        # 使用上面注册的方法获取队列
        dispatched_jobs = manager.get_dispatched_job_queue()
        finished_jobs = manager.get_finished_job_queue()

        job_id = 0
        module= self.project.modules[self.jobname];

        proj=json.loads(json.dumps(etl.convert_dict(self.project,self.project.__defaultdict__), ensure_ascii=False))
        while True:
            for task in etl.parallel_map(module):
                job_id = job_id + 1
                if job_id<skip:
                    continue
                job = ETLJob(proj, self.jobname, task, job_id);
                print('Dispatch job: %s' % job.id)
                dispatched_jobs.put(job)

            while not dispatched_jobs.empty():
                job = finished_jobs.get(60)
                print('Finished Job: %s, Count: %s' % (job.id, job.count))

            key=input('press any key to repeat,c to cancel')
            if key=='c':
                manager.shutdown()
                break
开发者ID:Veterun,项目名称:etlpy,代码行数:36,代码来源:distributed.py

示例3: __init__

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
 def __init__(self):
     self.config.read('config.ini')
     BaseManager.register('Queue', queue.Queue)
     manager = BaseManager()
     manager.start()
     self.queue = manager.Queue()
     self.threads = {
         'sensorreading_submitter': {
             'last_run': None,
             'timeout': int(self.config.get('api', 'submit_sensorreadings_interval')),
             'thread': None
         },
         'desired_state_fetcher': {
             'last_run': None,
             'timeout': int(self.config.get('api', 'fetch_desired_states_interval')),
             'thread': None
         },
         'sensorreading_buffer': {
             'last_run': None,
             'timeout': int(self.config.get('api', 'sensorreading_buffer_flush_interval')),
             'thread': None
         },
         'maintenance': {
             'last_run': None,
             'timeout': int(self.config.get('api', 'maintenance_interval')),
             'thread': None
         }
     }
开发者ID:dasprot,项目名称:ciliatus_controlunit,代码行数:30,代码来源:app.py

示例4: main

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
def main():
    BaseManager.register('run_rpc_function')
    manager = BaseManager(address=('127.0.0.1',51999), authkey='my_authkey')
    manager.connect()
    returned_proxy_object = manager.run_rpc_function('SOME LOUD TEXT')
    print returned_proxy_object
    print returned_proxy_object._getvalue() #might be a better way to get the value, probably need to specify my own proxy object, see BaseProxy
开发者ID:brentpayne,项目名称:ExampleCode,代码行数:9,代码来源:example_rpc_client.py

示例5: create

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
 def create(self, name, **ctor_args):
     ''' Create a :class:`ConsoleServer` and return a proxy for it. 
     '''
     manager = BaseManager()
     manager.register('ConsoleServer', ConsoleServer)
     manager.start()
     return manager.ConsoleServer()
开发者ID:JustinSGray,项目名称:OpenMDAO-Framework,代码行数:9,代码来源:consoleserverfactory.py

示例6: start

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
    def start(self):
        BaseManager.register('get_dispatch_queue',
                             callable=self.get_dispatch_queue)
        BaseManager.register('get_finished_queue',
                             callable=self.get_finished_queue)

        manager = BaseManager(address=('0.0.0.0', 8000),
                              authkey=b'dispatcher')
        manager.start()

        dispatch_queue = manager.get_dispatch_queue()
        finished_queue = manager.get_finished_queue()

        job_id = 0
        unfinished = self.rnd * self.batch
        for rnd in range(self.rnd):
            for i in range(self.batch):
                job = Job(job_id=job_id)
                job_id += 1
                print('Dispatch Job {}'.format(job))
                dispatch_queue.put(job)

            while not dispatch_queue.empty():
                finished_job = finished_queue.get(60)
                unfinished -= 1
                print('Job finished {}'.format(finished_job))
        dispatch_queue.put(None)
        while unfinished > 0:
            finished_job = finished_queue.get(60)
            unfinished -= 1
            print('Job finished {}'.format(finished_job))
        manager.shutdown()
开发者ID:Time1ess,项目名称:MyCodes,代码行数:34,代码来源:job_dispatch.py

示例7: i_images_processing

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
 def i_images_processing(self, vs): 
     
     """
     Interface function to launch processing VHRS images :func:`i_vhrs` and satellite images :func:`i_img_sat` in multi-processing.
     
     :param vs: Boolean variable to launch processing because of interface checkbox -> 0 or 1.
 
         - 0 means, not texture processing
         - 1 means, launch texture processing
     :type vs: int
     """
     
     # Multiprocessing
     mgr = BaseManager()
     mgr.register('defaultdict', defaultdict, DictProxy)
     mgr.start()
     self.out_ndvistats_folder_tab = mgr.defaultdict(list)
     
     p_img_sat = Process(target=self.i_img_sat)
     p_img_sat.start()
     if self.mp == 0:
         p_img_sat.join()
     
     if vs == 1:
         p_vhrs = Process(target=self.i_vhrs)#, args=(vs, ))
         p_vhrs.start()
         p_vhrs.join()
     
     if self.mp == 1:
         p_img_sat.join()
     
     # List of output raster path
     self.raster_path.append(self.out_ndvistats_folder_tab[0])
     # List of output raster band
     self.list_band_outraster.append(1)
     
     if vs == 1:
         self.raster_path.append(self.out_ndvistats_folder_tab['sfs'])
         self.list_band_outraster.append(4)
         self.raster_path.append(self.out_ndvistats_folder_tab['haralick'])
         self.list_band_outraster.append(2)
     
     # To slope, to extract scree
     if self.path_mnt != '':
         self.raster_path.append(self.path_mnt)
         self.list_band_outraster.append(1)
         
     self.raster_path.append(self.out_ndvistats_folder_tab[1])
     # example raster path tab :
     #                [path_folder_dpt + '/' + folder_processing + '/' + classif_year + '/Min_2014.TIF',\
     #                os.path.dirname(path_ortho) + '/Clip_buffer_surface_dep_18_IRCOrtho65_2m_sfs.TIF',\
     #                os.path.dirname(path_ortho) + '/Clip_buffer_surface_dep_18_IRCOrtho65_2m_haralick.TIF',\
     #                path_folder_dpt + '/' + folder_processing + '/' + classif_year + '/Max_2014.TIF']
     
     # List of output raster band
     self.list_band_outraster.append(1) #[1, 4, 2, 1]
     
     print("End of images processing !")
开发者ID:SylvioL,项目名称:PHYMOBAT,代码行数:60,代码来源:Processing.py

示例8: _setup

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
    def _setup(self):
        free_phy_mem = available_memory(percent=35)
        maxsize = int(free_phy_mem / BLOCK_SIZE)
        self._input_buffer = self.manager.Queue(maxsize)
        self.output_buffer = self.manager.Queue(maxsize)

        BaseManager.register("ReoderBuffer", ReoderBuffer)
        bm = BaseManager()
        bm.start()
        self.reorder_buffer = bm.ReoderBuffer(self.output_buffer, 50)
开发者ID:igorbonadio,项目名称:carbono,代码行数:12,代码来源:work_manager.py

示例9: StartConnect

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
 def StartConnect(self, serveraddress="localhost", port=80, key=None):
     if(self.queueManager == None):
         try:
             key = key.encode("utf-8")
         except:
             pass
         BaseManager.register('GetTaskQueue')
         BaseManager.register('GetResultQueue')
         queueManager = BaseManager(address=(serveraddress, port), authkey=key)
         queueManager.connect()
         self.queueManager = queueManager
开发者ID:zthxxx,项目名称:python-OpinionMonitoring,代码行数:13,代码来源:ProcessingQueueNode.py

示例10: StartManager

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
 def StartManager(self, serveraddress="Localhost", port=80, key=None):
     if(self.queueManager == None):
         try:
             key = key.encode("utf-8")
         except:
             pass
         BaseManager.register('GetTaskQueue', callable=ProcessingQueueManager.ReturnTaskQueue)
         BaseManager.register('GetResultQueue', callable=ProcessingQueueManager.ReturnResultQueue)
         queueManager = BaseManager(address=(serveraddress, port), authkey=key)
         queueManager.start()
         self.queueManager = queueManager
开发者ID:zthxxx,项目名称:python-OpinionMonitoring,代码行数:13,代码来源:ProcessingQueueManager.py

示例11: run

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
    def run(self, end_node):
        if self._mode == EXEC_MODE_BATCH:
            BaseManager.register('FlowStates', FlowStates)
            BaseManager.register('Node', Node)
            manager = BaseManager()
            manager.start()
            stat = manager.FlowStates()

            p = Process(target=self._run_batch, args=(end_node, stat))
            p.start()
            return stat
        elif self._mode == EXEC_MODE_STREAMING:
            self._run_streaming(end_node)
开发者ID:gangtao,项目名称:pyflow,代码行数:15,代码来源:flow.py

示例12: __init__

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
 def __init__(self, host=None, port=None, authkey=None, delmult=1, replaceterm=None, replacewith=None, name='1', delinprod=True):
     self.name = name
     self.host = host
     self.port = port
     self.authkey = authkey
     self.delinprod = delinprod
     print 'Initializing LogParser: ' + self.name + ' as BaseManager(address=(' + host + ', ' + str(port) + ', authkey=' + authkey + ') with remote queues'
     BaseManager.register('get_log_queue')
     self.m = BaseManager(address=(host, port), authkey=authkey)
     self.m.connect()
     self.queue = self.m.get_log_queue()
     self.delmult = delmult
     self.replaceterm = replaceterm
     self.replacewith = replacewith
开发者ID:daubman,项目名称:solr-replay,代码行数:16,代码来源:LogParser.py

示例13: analyze_found

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
 def analyze_found(self, list):
     if len(list) > 0:
         manager = BaseManager(address=('', self._share_port), authkey=self._auth)
         manager.register('get_meta_data')
         manager.connect()
         distances, max_dist = manager.get_meta_data()
         for n in list:
             try:
                 if max_dist - distances[n._id] > self._threshold:
                     # Do something here
                     print "*** Node " + str(n._id) + " hit the threshold"
             except KeyError:
                 # Do query here to see if node exists. If it does than node
                 # does not link to origin
                 print "*** Node " + str(n._id) + " may not link to origin"
开发者ID:admgrn,项目名称:Switcharoo,代码行数:17,代码来源:transverse.py

示例14: __init__

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
	def __init__(self):
		class QueueManager(BaseManager):
    			pass
    			# 由于这个QueueManager只从网络上获取Queue,所以注册时只提供名字:
		BaseManager.register('get_task_queue')
		BaseManager.register('get_result_queue')
		# 连接到服务器,也就是运行taskmanager.py的机器:
		server_addr = '10.1.142.100'
		print('Connect to server %s...' % server_addr)
		# 端口和验证码注意保持与taskmanager.py设置的完全一致:
		m = BaseManager(address=(server_addr, 8888), authkey='abc')
		# 从网络连接:
		m.connect()
		# 获取Queue的对象:
		self.task = m.get_task_queue()
		self.result = m.get_result_queue()
开发者ID:PatricKuo,项目名称:AFOJ-Core,代码行数:18,代码来源:judgeclient.py

示例15: __init__

# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import register [as 别名]
	def __init__(self):
		# 发送任务的队列:
		task_queue = Queue.Queue()
		# 接收结果的队列:
		result_queue = Queue.Queue()
		class QueueManager(BaseManager):
		    pass
		# 把两个Queue都注册到网络上, callable参数关联了Queue对象:
		BaseManager.register('get_task_queue', callable=lambda: task_queue)
		BaseManager.register('get_result_queue', callable=lambda: result_queue)
		# 绑定端口5000, 设置验证码'abc':
		manager = BaseManager(address=('',8888), authkey='abc')
		# 启动Queue:
		manager.start()
		# 获得通过网络访问的Queue对象:
		self.task = manager.get_task_queue()
		self.result = manager.get_result_queue()
开发者ID:PatricKuo,项目名称:AFOJ-Core,代码行数:19,代码来源:Judge.py


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