本文整理汇总了Python中multiprocessing.managers.BaseManager类的典型用法代码示例。如果您正苦于以下问题:Python BaseManager类的具体用法?Python BaseManager怎么用?Python BaseManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
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()
示例2: run
def run(self):
while not self.is_stop:
mgr = BaseManager(address=('', 7777), authkey='xxx')
s = mgr.get_server()
s.serve_forever()
i = 1
i += 1
示例3: __init__
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
}
}
示例4: make_simple_server_manager
def make_simple_server_manager(ip,port, authkey):
print "starting server..."
manager = BaseManager(address=('', 50000), authkey='abc')
server = manager.get_server()
server.serve_forever()
print "started"
return manager
示例5: __init__
def __init__(self,address='127.0.0.1',port=6666,authkey='',rootDomain='',digSubDomain=False,threads_num=1):
BaseManager.__init__(self,(address,int(port)),authkey)
task_queue_n=Queue.Queue()
response_queue_n=Queue.Queue()
# self.address=address
self.port=port
self.authkey=authkey
self.register('task_queue_n',callable=lambda:task_queue_n)
self.register('response_queue_n',callable=lambda:response_queue_n)
# self.tasks=[] #记录自己已经访问过的域名,或者路径
self.digSubDomain=digSubDomain
self.DnsThread=None
self.httpserverThread=None
self.START_FLAG=True
self.count=0 #访问错误计数
self.delay=0 #延时时间
self.threads_num=threads_num #爆破子域名的线程数
if self.digSubDomain:
self.domain=domainRecorder(rootDomain=rootDomain,domain=rootDomain,path='/',isSubDomain=True)
else:
self.domain=domainRecorder(rootDomain=rootDomain,domain=rootDomain,path='/',isSubDomain=False)
self.domainCount=0
示例6: __init__
def __init__(self, address=None, authkey=None, serialize='pickle',
ctx=None):
BaseManager.__init__(self, address, authkey, serialize, ctx)
self.task_queue, self.result_queue = None, None
# callable使用lambda报错
self.register('get_task_queue', callable=return_task_queue)
self.register('get_result_queue', callable=return_result_queue)
示例7: start
def start(self):
BaseManager.start(self)
# 加载任务队列和结果队列
if not self.task_queue:
self.task_queue = self.get_task_queue()
if not self.result_queue:
self.result_queue = self.get_result_queue()
示例8: _setup
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)
示例9: __init__
def __init__(self, address, authkey):
BaseManager.__init__(self, address, authkey)
self.srvAddr = address
self.srvKey = authkey
AgentManager.register("get")
AgentManager.register("load")
AgentManager.register("readFile")
AgentManager.register("writeFile")
AgentManager.register("printmsg")
self.localattrs = dict()
示例10: __init__
def __init__(self):
BaseManager.__init__(self,address=(Parameter.SERVER, Parameter.PORT), authkey=Parameter.PASSWORD)
self._manager = Manager()
self._coordinates = self._manager.Queue()
self._values = self._manager.Queue()
self._lock = self._manager.Lock()
self._clientCounter = self._manager.Value('i', 0)
self.register('clientStart', self.addClient)
self.register('clientDone', self.removeClient)
self.register('getCoordinatesLock', self.getCoordinatesLock)
self.register('getCoordinatesQueue', self.getCoordinates)
self.register('getValuesQueue', self.getValues)
示例11: __init__
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
示例12: connect
def connect(self, pythonexec=None, parent=None):
"Custom connection method that will start up a new server"
# fork a new server process with correct python interpreter (py3/venv)
if pythonexec:
# warning: this will not work frozen? (ie. py2exe)
command = pythonexec + " -u %s --server" % __file__
import wx
class MyProcess(wx.Process):
"Custom Process Class to handle OnTerminate event method"
def OnTerminate(self, pid, status):
"Clean up on termination (prevent SEGV!)"
def OnClose(self, evt):
"Termitate the process on exit"
# prevent the server continues running after the IDE closes
print("closing pid", self.GetPid())
self.Kill(self.GetPid())
print("killed")
self.process = MyProcess(parent)
parent.Bind(wx.EVT_CLOSE, self.process.OnClose)
#process.Redirect()
flags = wx.EXEC_ASYNC
if wx.Platform == '__WXMSW__':
flags |= wx.EXEC_NOHIDE
wx.Execute(command, flags, self.process)
return BaseManager.connect(self)
示例13: QueueServer
class QueueServer(object):
def __init__(self, queue_server_host, queue_server_port, queue_server_authkey=None):
'''
host,port defines where your queuing server should be running while *authkey*
is going to be used to authenticate any communication between this queue server
and clients connected to it. Clients will need to send the *authkey* to connect
this queue server.
'''
self.host = queue_server_host
self.port = queue_server_port
self.authkey = queue_server_authkey
'''
Lets just say, we have a client that wants to put some image realted data into database
and also want to generate thumbnails from it (You know, where it is going,
I'll give you a hint, checkout my last post about multi-threading)
'''
database_queue = Queue()
thumbnail_queue = Queue()
'''now we have a queue, but if since we want our clients to use it
we'll need to register this queue with BaseManager via some callable that our client
can use to generate the proxy object. Yes, clients will be actually
able to get the (proxy) object of this Queue and for them, they can
pretty much use it like a regular queue (however, internally, BaseManager
will be proxying that data sharing between client and server (and thats the
fun, we don't have to worry about locking, shared memory handling etc as
BaseManager will handle that, and for us it will be like using Queue between
threads'''
BaseManager.register('database_queue', callable=lambda:database_queue)
BaseManager.register('thumbnail_queue', callable=lambda:thumbnail_queue)
'''Now that we have registered our queue with BaseManager, we can instantiate
manager object and start the server. As mentioned, BaseManager will spawn a
server in a subprocess and will handle all the communcation and data synchronization'''
self.manager = BaseManager(address=(self.host, self.port),
authkey=self.authkey)
def start(self):
print 'Starting Server Process...'
self.manager.start()
def stop(self):
self.manager.shutdown()
示例14: start
def start(self, controller):
self.controller = controller
self.register('get_controller', self.get_controller)
if not self.try_next_port:
self.get_server().serve_forever()
host, port = self.address
while self.try_next_port:
try:
BaseManager.__init__(self, (host,port), self.authkey)
self.get_server().serve_forever()
self.try_next_port = False
except socket.error as e:
try_next_port = False
import errno
if e.errno == errno.EADDRINUSE:
port += 1
else:
raise
示例15: __init__
def __init__(self):
BaseManager.register('get_task_queue')
BaseManager.register('get_result_queue')
server_addr = '127.0.0.1'
print ('Connect to server %s...' % server_addr)
self.m=BaseManager(address=(server_addr,8001),authkey='qiye'.encode('utf-8'))
print 'connecting...'
self.m.connect()
print 'connected'
self.task = self.m.get_task_queue()
self.result = self.m.get_result_queue()
self.downloader = HtmlDownloader()
self.parser = HtmlParser()
print 'spider init finish'