本文整理汇总了Python中zmq.REQ属性的典型用法代码示例。如果您正苦于以下问题:Python zmq.REQ属性的具体用法?Python zmq.REQ怎么用?Python zmq.REQ使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类zmq
的用法示例。
在下文中一共展示了zmq.REQ属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [as 别名]
def __init__(self, max_nprocs):
import subprocess
import sys
import os
import zmq
# Since the output terminals are used for lots of debug output etc., we use
# ZeroMQ to communicate with the workers.
zctx = zmq.Context()
socket = zctx.socket(zmq.REQ)
port = socket.bind_to_random_port("tcp://*")
cmd = 'import %s as mod; mod._mpi_worker("tcp://127.0.0.1:%d")' % (__name__, port)
env = dict(os.environ)
env['PYTHONPATH'] = ':'.join(sys.path)
self.child = subprocess.Popen(['mpiexec', '-np', str(max_nprocs), sys.executable,
'-c', cmd], env=env)
self.socket = socket
示例2: test_hwm
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [as 别名]
def test_hwm(self):
zmq3 = zmq.zmq_version_info()[0] >= 3
for stype in (zmq.PUB, zmq.ROUTER, zmq.SUB, zmq.REQ, zmq.DEALER):
s = self.context.socket(stype)
s.hwm = 100
self.assertEqual(s.hwm, 100)
if zmq3:
try:
self.assertEqual(s.sndhwm, 100)
except AttributeError:
pass
try:
self.assertEqual(s.rcvhwm, 100)
except AttributeError:
pass
s.close()
示例3: test_monitor_connected
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [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")
示例4: test_single_socket_forwarder_connect
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [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()
示例5: __init__
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [as 别名]
def __init__(self, reqAddress, subAddress):
"""Constructor"""
super(RpcClient, self).__init__()
# zmq端口相关
self.__reqAddress = reqAddress
self.__subAddress = subAddress
self.__context = zmq.Context()
self.__socketREQ = self.__context.socket(zmq.REQ) # 请求发出socket
self.__socketSUB = self.__context.socket(zmq.SUB) # 广播订阅socket
# 工作线程相关,用于处理服务器推送的数据
self.__active = False # 客户端的工作状态
self.__thread = threading.Thread(target=self.run) # 客户端的工作线程
#----------------------------------------------------------------------
示例6: main
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [as 别名]
def main():
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://%s:%s" % (config.LISTEN_ON_IP, config.LISTEN_ON_PORT))
while True:
command = input("Command: ")
socket.send(command.encode(config.CODEC))
response = socket.recv().decode(config.CODEC)
print(" ... %s" % response)
words = shlex.split(response.lower())
status = words[0]
if len(words) > 1:
info = words[1:]
if status == "finished":
print("Finished status received from robot")
break
示例7: __init__
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [as 别名]
def __init__(self, exchange='', addr='ipc:///tmp/feed.ipc', timeout=30):
"""
:param period: int: Data sampling period
:param pairs: list: Pair symbols to trade
:param exchange: str: FeedDaemon exchange to query
:param addr: str: Client socked address
:param timeout: int:
"""
super(DataFeed, self).__init__()
# Sock objects
self.context = zmq.Context()
self.addr = addr
self.exchange = exchange
self.timeout = timeout * 1000
self.sock = self.context.socket(zmq.REQ)
self.sock.connect(addr)
self.poll = zmq.Poller()
self.poll.register(self.sock, zmq.POLLIN)
示例8: __init__
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [as 别名]
def __init__(self, client_name):
"""This function estabilish the connection to EXASolution"""
self.z = z
self.connection_id = 0
self.req = z.exascript_request()
self.rep = z.exascript_response()
self.client_name = client_name
self.zcontext = zmq.Context()
self.zsocket = self.zcontext.socket(zmq.REQ)
if self.client_name.startswith('tcp://'):
self.zsocket.bind(self.client_name)
elif self.client_name.startswith('unix://'):
self.zsocket.connect(self.client_name)
elif self.client_name.startswith('ipc://'):
self.zsocket.connect(self.client_name)
else: raise RuntimeError("Unsupported protocol, supported are only ipc://, tcp://, and unix://")
示例9: _open_zmq_connection
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [as 别名]
def _open_zmq_connection(self):
'''
Connects to the raspberry via zmq/tcp
Input:
None
Output:
None
'''
self.context = zmq.Context(1)
print("Connecting to Raspberry Pi")
self.client = self.context.socket(zmq.REQ)
self.client.connect("tcp://%s:%s"%(self._address,self._port)) # raspi address
self.poll = zmq.Poller()
self.poll.register(self.client, zmq.POLLIN)
示例10: main
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [as 别名]
def main() -> None:
logging.basicConfig(level=logging.INFO)
LEVELS = {
"nano": 0,
"mini": 1,
"heavyduty": 2,
}
parser = argparse.ArgumentParser(description="Simple benchmark utility.")
parser.add_argument(
"--ursadb",
help="URL of the ursadb instance.",
default="tcp://localhost:9281",
)
parser.add_argument(
"--level",
help="How hard should the tests be.",
choices=LEVELS.keys(),
default="heavyduty",
)
args = parser.parse_args()
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.setsockopt(zmq.LINGER, 0)
socket.connect(args.ursadb)
level = LEVELS[args.level]
if level >= 0:
nano(socket)
if level >= 1:
mini(socket)
if level >= 2:
heavyduty(socket)
示例11: rr_socket
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [as 别名]
def rr_socket(self):
socket = self.test_context.socket(zmq.REQ)
socket.connect(self.rr_endpoint)
yield socket
socket.close(linger=1)
示例12: run
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [as 别名]
def run(engine, source_name, server_address, all_responses_required=False,
timeout=TEN_SECONDS, request_retries=REQUEST_RETRIES):
context = zmq.Context()
while request_retries > 0:
socket = context.socket(zmq.REQ)
socket.connect(server_address)
from_standalone_engine = gabriel_pb2.FromStandaloneEngine()
from_standalone_engine.welcome.source_name = source_name
from_standalone_engine.welcome.all_responses_required = (
all_responses_required)
socket.send(from_standalone_engine.SerializeToString())
logger.info('Sent welcome message to server')
while True:
if socket.poll(timeout) == 0:
logger.warning('No response from server')
socket.setsockopt(zmq.LINGER, 0)
socket.close()
request_retries -= 1
break
message_from_server = socket.recv()
if message_from_server == network_engine.HEARTBEAT:
socket.send(network_engine.HEARTBEAT)
continue
input_frame = gabriel_pb2.InputFrame()
input_frame.ParseFromString(message_from_server)
result_wrapper = engine.handle(input_frame)
from_standalone_engine = gabriel_pb2.FromStandaloneEngine()
from_standalone_engine.result_wrapper.CopyFrom(result_wrapper)
socket.send(from_standalone_engine.SerializeToString())
logger.warning('Ran out of retires. Abandoning server connection.')
示例13: test_warn_set_timeo
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [as 别名]
def test_warn_set_timeo(self):
s = self.context.socket(zmq.REQ)
with warnings.catch_warnings(record=True) as w:
s.rcvtimeo = 5
s.close()
self.assertEqual(len(w), 1)
self.assertEqual(w[0].category, UserWarning)
示例14: test_warn_get_timeo
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [as 别名]
def test_warn_get_timeo(self):
s = self.context.socket(zmq.REQ)
with warnings.catch_warnings(record=True) as w:
s.sndtimeo
s.close()
self.assertEqual(len(w), 1)
self.assertEqual(w[0].category, UserWarning)
示例15: test_sockopts
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import REQ [as 别名]
def test_sockopts(self):
"""setting socket options with ctx attributes"""
ctx = self.Context()
ctx.linger = 5
self.assertEqual(ctx.linger, 5)
s = ctx.socket(zmq.REQ)
self.assertEqual(s.linger, 5)
self.assertEqual(s.getsockopt(zmq.LINGER), 5)
s.close()
# check that subscribe doesn't get set on sockets that don't subscribe:
ctx.subscribe = b''
s = ctx.socket(zmq.REQ)
s.close()
ctx.term()