本文整理汇总了Python中multiprocessing.managers.SyncManager.get_server方法的典型用法代码示例。如果您正苦于以下问题:Python SyncManager.get_server方法的具体用法?Python SyncManager.get_server怎么用?Python SyncManager.get_server使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.managers.SyncManager
的用法示例。
在下文中一共展示了SyncManager.get_server方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_binary_matrix_from_service
# 需要导入模块: from multiprocessing.managers import SyncManager [as 别名]
# 或者: from multiprocessing.managers.SyncManager import get_server [as 别名]
def get_binary_matrix_from_service(q):
global matrix_service
if matrix_service == None:
matrices = dict()
matrix_service = SyncManager(address=("localhost", 50000), authkey="")
SyncManager.register("get_matrix", lambda q: get_matrix(q, matrices))
Process(target=lambda: matrix_service.get_server().serve_forever()).start()
SyncManager.register("get_matrix")
matrix_service.connect()
return matrix_service.get_matrix(q)
示例2: Queue
# 需要导入模块: from multiprocessing.managers import SyncManager [as 别名]
# 或者: from multiprocessing.managers.SyncManager import get_server [as 别名]
class Queue(Daemon):
"""
Creates remote methods for creating/deleteing streams,
and accessing the Streams priority queue, data-store and
properties.
"""
def __init__(self, address, authkey, logdir= curdir, piddir= curdir):
self.streams= {}
self.address= address
self.manager= SyncManager(address= self.address, authkey= authkey)
self.manager.register("create_stream", callable= self.create_stream)
self.manager.register("delete_stream", callable= self.delete_stream)
self.manager.register("get_streams", callable= lambda: self.streams, proxytype= DictProxy)
self.manager.register("get_store", callable= lambda id: self.streams[id].store, proxytype= DictProxy)
self.manager.register("get_queue", callable= lambda id: self.streams[id].queue, proxytype= PriorityQueue)
self.manager.register("get_properties", callable= lambda id: self.streams[id].properties, proxytype= DictProxy)
super(Queue, self).__init__(
pidfile= path.join(piddir, self.__class__.__name__ + ".pid"),
stdout= path.join(logdir, self.__class__.__name__ + ".out"),
stderr= path.join(logdir, self.__class__.__name__ + ".err"),
stdin= path.join(logdir, self.__class__.__name__ + ".in")
)
def create_stream(self, **properties):
"""
Creates stream and returns a unique stream identifier
to the caller. If an identifier was passed in by the caller
that identifier will be used to create the stream. If the
stream already exists then now new stream is created and the
existing stream is reused.
"""
stream= Stream(**properties)
try:
stream= self.streams[stream.id]
except KeyError:
self.streams[stream.id]= stream
print "created stream", stream.id, properties
def delete_stream(self, id):
"""Deletes the stream of the given identifier."""
del self.streams[id]
print "deleting stream", id
def run(self):
"""Starts up the Queue server and starts listing for requests."""
server= self.manager.get_server()
print "running"
server.serve_forever()
示例3: Manager
# 需要导入模块: from multiprocessing.managers import SyncManager [as 别名]
# 或者: from multiprocessing.managers.SyncManager import get_server [as 别名]
import sys
import os
import multiprocessing
from multiprocessing.managers import SyncManager
sys.path.append(os.path.realpath('.'))
sys.path.append(os.path.realpath('../'))
from helpers.instrumentsmanager import *
print "Initializing instruments..."
MyManager = Manager()
#The temperature
temperature = MyManager.getInstrument("temperature")
print temperature.temperature()
if __name__ == "__main__":
manager = SyncManager(address=('localhost', 50000), authkey='abc')
manager.register('get_manager', callable=lambda:MyManager)
server = manager.get_server()
server.serve_forever()