本文整理汇总了Python中zmq.REP属性的典型用法代码示例。如果您正苦于以下问题:Python zmq.REP属性的具体用法?Python zmq.REP怎么用?Python zmq.REP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类zmq
的用法示例。
在下文中一共展示了zmq.REP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def setUp(self):
super(TestZMQWorkerBasic,self).setUp()
self.rr_endpoint = self.make_endpoint()
self.ann_endpoint = self.make_endpoint()
# Need to bind ann_socket here in setup, because if we bind it during
# tests, messages get lost.
self.ann_socket = self.test_context.socket(zmq.PUB)
self.ann_socket.bind(self.ann_endpoint)
# If we're binding ann_socket, we might as well bind rr_socket
self.rr_socket = self.test_context.socket(zmq.REP)
self.rr_socket.bind(self.rr_endpoint)
self.test_worker = ZMQWorker(self.rr_endpoint, self.ann_endpoint)
self.test_worker.validation_fail_action = 'raise'
self.test_worker.shutdown_timeout = 0.5
self.test_worker.master_beacon_period = BEACON_PERIOD
self.test_worker.startup()
self.test_core.master_id = self.test_core.node_id
time.sleep(SETUP_WAIT)
示例2: test_monitor_connected
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def test_monitor_connected(self):
"""Test connected monitoring socket."""
s_rep = self.context.socket(zmq.REP)
s_req = self.context.socket(zmq.REQ)
self.sockets.extend([s_rep, s_req])
s_req.bind("tcp://127.0.0.1:6667")
# try monitoring the REP socket
# create listening socket for monitor
s_event = s_rep.get_monitor_socket()
s_event.linger = 0
self.sockets.append(s_event)
# test receive event for connect event
s_rep.connect("tcp://127.0.0.1:6667")
m = recv_monitor_message(s_event)
if m['event'] == zmq.EVENT_CONNECT_DELAYED:
self.assertEqual(m['endpoint'], b"tcp://127.0.0.1:6667")
# test receive event for connected event
m = recv_monitor_message(s_event)
self.assertEqual(m['event'], zmq.EVENT_CONNECTED)
self.assertEqual(m['endpoint'], b"tcp://127.0.0.1:6667")
示例3: test_single_socket_forwarder_connect
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def test_single_socket_forwarder_connect(self):
if zmq.zmq_version() in ('4.1.1', '4.0.6'):
raise SkipTest("libzmq-%s broke single-socket devices" % zmq.zmq_version())
dev = devices.ThreadDevice(zmq.QUEUE, zmq.REP, -1)
req = self.context.socket(zmq.REQ)
port = req.bind_to_random_port('tcp://127.0.0.1')
dev.connect_in('tcp://127.0.0.1:%i'%port)
dev.start()
time.sleep(.25)
msg = b'hello'
req.send(msg)
self.assertEqual(msg, self.recv(req))
del dev
req.close()
dev = devices.ThreadDevice(zmq.QUEUE, zmq.REP, -1)
req = self.context.socket(zmq.REQ)
port = req.bind_to_random_port('tcp://127.0.0.1')
dev.connect_out('tcp://127.0.0.1:%i'%port)
dev.start()
time.sleep(.25)
msg = b'hello again'
req.send(msg)
self.assertEqual(msg, self.recv(req))
del dev
req.close()
示例4: starting
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def starting(self):
"""Create a ZMQ context and socket to handle TCP communication."""
if self.parent is None:
raise RuntimeError("Parent pool was not set - cannot start.")
self._zmq_context = zmq.Context()
self._sock = self._zmq_context.socket(zmq.REP)
if self.parent.cfg.port == 0:
port_selected = self._sock.bind_to_random_port(
"tcp://{}".format(self.parent.cfg.host)
)
else:
self._sock.bind(
"tcp://{}:{}".format(
self.parent.cfg.host, self.parent.cfg.port
)
)
port_selected = self.parent.cfg.port
self._address = "{}:{}".format(self.parent.cfg.host, port_selected)
super(ZMQServer, self).starting()
示例5: __init__
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def __init__(self, path=None, port=None, pull=False):
try:
import zmq
except ImportError as err:
print("ImportError: {0}".format(err))
sys.exit("Need zmq installed.")
self.pull = pull or port
context = zmq.Context()
self.socket = context.socket(zmq.PULL if self.pull else zmq.REP)
if path:
self.socket.bind("ipc://" + path)
elif port:
self.socket.bind("tcp://127.0.0.1:%d" % port)
else:
raise Exception("Must specify path or port.")
self.messages = None
示例6: _init_server
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def _init_server(self):
infer_model = InferenceModel(
model_dir=self.model_dir,
gpu_mem_frac=self.gpu_mem_frac,
use_gpu=True,
batch_size=self.batch_size,
beam_width=self.beam_width,
maximum_iterations=self.maximum_iterations
)
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.connect("tcp://localhost:%s" % self.port_backend)
print("Server running on GPU ", os.environ['CUDA_VISIBLE_DEVICES'])
while True:
inp = json.loads(socket.recv())
if inp[0]:
embeddings = infer_model.seq_to_emb(inp[1])
socket.send_string(json.dumps(embeddings.tolist()))
else:
smiles = infer_model.emb_to_seq(np.array(inp[1]))
socket.send_string(json.dumps(smiles))
示例7: __init__
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def __init__(self, repAddress, pubAddress):
"""Constructor"""
super(RpcServer, self).__init__()
# 保存功能函数的字典,key是函数名,value是函数对象
self.__functions = {}
# zmq端口相关
self.__context = zmq.Context()
self.__socketREP = self.__context.socket(zmq.REP) # 请求回应socket
self.__socketREP.bind(repAddress)
self.__socketPUB = self.__context.socket(zmq.PUB) # 数据广播socket
self.__socketPUB.bind(pubAddress)
# 工作线程相关
self.__active = False # 服务器的工作状态
self.__thread = threading.Thread(target=self.run) # 服务器的工作线程
#----------------------------------------------------------------------
示例8: __init__
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def __init__(self, queue):
self.queue = queue
self.io_loop = IOLoop(make_current=False)
context = zmq.Context.instance()
self.pause_socket = context.socket(zmq.REP)
self.pause_socket_port = self.pause_socket.bind_to_random_port(
"tcp://127.0.0.1")
self.status_socket = context.socket(zmq.PULL)
self.status_socket_port = self.status_socket.bind_to_random_port(
"tcp://127.0.0.1")
self.pause_stream = ZMQStream(self.pause_socket, self.io_loop)
self.status_stream = ZMQStream(self.status_socket, self.io_loop)
self.pause_stream.on_recv(self.recv_pause)
self.status_stream.on_recv(self.recv_status)
self.thread = threading.Thread(target=self._thread_main)
self.thread.daemon = True
示例9: run
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def run(self):
enable_death_signal(_warn=self.identity == b'0')
ctx = zmq.Context()
socket = ctx.socket(zmq.REP)
socket.setsockopt(zmq.IDENTITY, self.identity)
socket.set_hwm(self.hwm)
socket.connect(self.pipename)
while True:
dp = loads(socket.recv(copy=False))
dp = self.map_func(dp)
socket.send(dumps(dp), copy=False)
示例10: _mpi_worker
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def _mpi_worker(addr):
import importlib
import zmq
from pickle import loads, dumps
rank = MPI.COMM_WORLD.Get_rank()
if rank == 0:
zctx = zmq.Context()
socket = zctx.socket(zmq.REP)
socket.connect(addr)
while True:
if rank == 0:
pickled_msg = socket.recv()
else:
pickled_msg = None
pickled_msg = MPI.COMM_WORLD.bcast(pickled_msg, root=0)
msg = loads(pickled_msg)
if msg == 'stop':
if rank == 0:
socket.send_pyobj('')
break
else:
module_name, func_name = msg
mod = importlib.import_module(module_name)
func = getattr(mod, func_name)
status = func(_return_status=True)
if rank == 0:
socket.send_pyobj(status)
# All processes wait until they can terminate
MPI.COMM_WORLD.barrier()
示例11: create_poller
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def create_poller(worker_address, frontend_address):
context = zmq.Context()
worker_socket = context.socket(zmq.PULL)
worker_socket.bind(worker_address)
frontend_socket = context.socket(zmq.REP)
frontend_socket.bind(frontend_address)
sockets = {
"worker": {"socket": worker_socket, "receive": worker_socket.recv, "send": worker_socket.send_json},
"frontend": {"socket": frontend_socket, "receive": frontend_socket.recv, "send": frontend_socket.send},
}
time_func = time.time
return Poller(sockets, time_func)
示例12: create_poller
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def create_poller(frontend_address):
from cloudasr import Poller
context = zmq.Context()
frontend_socket = context.socket(zmq.REP)
frontend_socket.bind(frontend_address)
sockets = {
"frontend": {"socket": frontend_socket, "receive": frontend_socket.recv, "send": frontend_socket.send},
}
time_func = time.time
return Poller(sockets, time_func)
示例13: start
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def start(self):
"""Create and bind the ZAP socket"""
self.zap_socket = self.context.socket(zmq.REP)
self.zap_socket.linger = 1
self.zap_socket.bind("inproc://zeromq.zap.01")
self.log.debug("Starting")
示例14: test_again
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def test_again(self):
s = self.context.socket(zmq.REP)
self.assertRaises(Again, s.recv, zmq.NOBLOCK)
self.assertRaisesErrno(zmq.EAGAIN, s.recv, zmq.NOBLOCK)
s.close()
示例15: atest_ctxterm
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REP [as 别名]
def atest_ctxterm(self):
s = self.context.socket(zmq.REP)
t = Thread(target=self.context.term)
t.start()
self.assertRaises(ContextTerminated, s.recv, zmq.NOBLOCK)
self.assertRaisesErrno(zmq.TERM, s.recv, zmq.NOBLOCK)
s.close()
t.join()