本文整理汇总了Python中zmq.select方法的典型用法代码示例。如果您正苦于以下问题:Python zmq.select方法的具体用法?Python zmq.select怎么用?Python zmq.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmq
的用法示例。
在下文中一共展示了zmq.select方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_tcp_connection
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import select [as 别名]
def check_tcp_connection(addr_port):
sock = socket.socket()
addr, port = addr_port.split(':')
try:
sock.connect((addr, int(port)))
sock.send(TEST_MSG.encode())
except OSError as e:
print("TCP CHECK PHASE::: Cannot connect to {} because\n {}".format(addr_port, e))
return False
print("TCP CHECK PHASE:::Waiting {} seconds for response from server".format(WAIT_TIMEOUT))
ready = select.select([sock], [], [], WAIT_TIMEOUT)
if ready[0]:
reply = sock.recv(1024)
reply = reply.decode()
print("TCP CHECK PHASE::: Got reply {}".format(reply))
if reply != EXPECTED_TCP_REPLY:
print("TCP CHECK PHASE:::TCP connection test failed. \nGot {} \nbut expected reply {}\n".format(reply, EXPECTED_TCP_REPLY))
print("TCP CHECK PHASE:::Got expected response")
return True
return False
开发者ID:hyperledger,项目名称:indy-plenum,代码行数:24,代码来源:client.py示例2: test_pair
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import select [as 别名]
def test_pair(self):
s1, s2 = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
# Sleep to allow sockets to connect.
wait()
rlist, wlist, xlist = zmq.select([s1, s2], [s1, s2], [s1, s2])
self.assert_(s1 in wlist)
self.assert_(s2 in wlist)
self.assert_(s1 not in rlist)
self.assert_(s2 not in rlist)
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:13,代码来源:test_poll.py示例3: test_timeout
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import select [as 别名]
def test_timeout(self):
"""make sure select timeout has the right units (seconds)."""
s1, s2 = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
tic = time.time()
r,w,x = zmq.select([s1,s2],[],[],.005)
toc = time.time()
self.assertTrue(toc-tic < 1)
self.assertTrue(toc-tic > 0.001)
tic = time.time()
r,w,x = zmq.select([s1,s2],[],[],.25)
toc = time.time()
self.assertTrue(toc-tic < 1)
self.assertTrue(toc-tic > 0.1)
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:15,代码来源:test_poll.py示例4: _select_recv
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import select [as 别名]
def _select_recv(self, multipart, socket, **kwargs):
"""call recv[_multipart] in a way that raises if there is nothing to receive"""
if zmq.zmq_version_info() >= (3,1,0):
# zmq 3.1 has a bug, where poll can return false positives,
# so we wait a little bit just in case
# See LIBZMQ-280 on JIRA
time.sleep(0.1)
r,w,x = zmq.select([socket], [], [], timeout=kwargs.pop('timeout', 5))
assert len(r) > 0, "Should have received a message"
kwargs['flags'] = zmq.DONTWAIT | kwargs.get('flags', 0)
recv = socket.recv_multipart if multipart else socket.recv
return recv(**kwargs)
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:16,代码来源:__init__.py示例5: check_zmq_connection
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import select [as 别名]
def check_zmq_connection(addr_port):
ctx = zmq.Context()
sock = ctx.socket(zmq.DEALER)
l_pub_key, l_sec_key = zmq.curve_keypair()
sock.setsockopt(zmq.IDENTITY, base64.encodebytes(l_pub_key))
sock.setsockopt(zmq.CURVE_PUBLICKEY, l_pub_key)
sock.setsockopt(zmq.CURVE_SECRETKEY, l_sec_key)
dest = get_dest(SERVER_SEED)
sock.setsockopt(zmq.CURVE_SERVERKEY, z85.encode(ed_25519_pk_to_curve_25519(base58.b58decode(dest))))
try:
sock.connect("{}://{}".format(ZMQ_NETWORK_PROTOCOL, addr_port))
sock.send_string(TEST_MSG)
except OSError as e:
print("ZMQ CHECK PHASE::: Cannot connect to {} because\n {}".format(addr_port, e))
return False
print("ZMQ CHECK PHASE:::Waiting {} seconds for response from server".format(WAIT_TIMEOUT))
ready = zmq.select([sock], [], [], WAIT_TIMEOUT)
if ready[0]:
reply = sock.recv(flags=zmq.NOBLOCK)
reply = reply.decode()
print("ZMQ CHECK PHASE::: Got reply {}".format(reply))
if reply != EXPECTED_ZMQ_REPLY:
print("ZMQ CHECK PHASE:::ZMQ connection test failed. \nGot {} \nbut expected reply {}\n".format(reply, EXPECTED_ZMQ_REPLY))
print("ZMQ CHECK PHASE:::Got expected response")
return True
return False
开发者ID:hyperledger,项目名称:indy-plenum,代码行数:32,代码来源:client.py示例6: listener
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import select [as 别名]
def listener():
cnt=0
while 1:
while len(zmq.select([zmq_sub],[],[],0.001)[0])>0:
topic, info, data = zmq_sub.recv_multipart()
#topic=topic.decode()
info=struct.unpack('llll',info)
shape=info[:3]
frame_cnt=info[3]
img=np.fromstring(data,'uint8').reshape(shape)
rgb=img[...,::-1]
if cvshow:
#if 'depth' in topic:
# cv2.imshow(topic,img)
#else:
#cv2.imshow(topic,cv2.resize(cv2.resize(img,(1920/2,1080/2)),(512,512)))
img_shrk = img[::2,::2]
cv2.imshow(topic.decode(),img)
cv2.waitKey(1)
if topic==topicm and gst:
stdin.write(rgb.tostring())
### test
time.sleep(0.010)
if cnt%20==0:
print('send...',cnt)
if test:
time.sleep(0.020)
stdin.write(b'23\xff'*(sx*sy))
cnt+=1
开发者ID:orig74,项目名称:DroneSimLab,代码行数:31,代码来源:ue4_image_bridge.py示例7: main_loop
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import select [as 别名]
def main_loop(gworld):
drone_actor=ph.FindActorByName(gworld,'Parrot_Drone_6',1)
#drone_camera_actor=ph.FindActorByName(gworld,'SceneCapture2Ddrone',1)
if drone_actor is None:# or drone_camera_actor is None:
print('ERROR: could not find drone_actor')
while 1:
yield
for _ in range(10): #need to send it a few time don't know why.
socket_pub.send_multipart([config.topic_unreal_state,b'main_loop'])
yield
drone_start_pos=np.array(ph.GetActorLocation(drone_actor))
position=None
while 1:
while len(zmq.select([socket_sub],[],[],0)[0])>0:
topic, msg = socket_sub.recv_multipart()
position=pickle.loads(msg)
if position is not None:
new_pos=drone_start_pos+np.array([position['posx'],position['posy'],position['posz']])*100 #turn to cm
ph.SetActorLocation(drone_actor,new_pos)
ph.SetActorRotation(drone_actor,(position['roll'],position['pitch'],position['yaw']))
#incase of gimabl
#ph.SetActorRotation(drone_camera_actor,(-position['roll'],-position['pitch'],-position['yaw']))
position=None
yield
img1=cv2.resize(ph.GetTextureImg(),(512,512),cv2.INTER_LINEAR)
cv2.imshow('camera 1',img1)
cv2.waitKey(1)
开发者ID:orig74,项目名称:DroneSimLab,代码行数:29,代码来源:unreal_proxy.py示例8: listener
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import select [as 别名]
def listener():
while 1:
while len(zmq.select([zmq_sub],[],[],0.001)[0])>0:
topic, shape, data = zmq_sub.recv_multipart()
topic=topic.decode()
shape=struct.unpack('lll',shape)
img=np.fromstring(data,'uint8').reshape(shape)
if cvshow:
if 'depth' in topic:
cv2.imshow(topic,img)
else:
cv2.imshow(topic,cv2.resize(cv2.resize(img,(1024,1024)),(512,512)))
cv2.waitKey(1)
开发者ID:orig74,项目名称:DroneSimLab,代码行数:15,代码来源:ue4_image_viewer.py示例9: _connect
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import select [as 别名]
def _connect(self, sshserver, ssh_kwargs, timeout):
"""setup all our socket connections to the cluster. This is called from
__init__."""
# Maybe allow reconnecting?
if self._connected:
return
self._connected=True
def connect_socket(s, url):
if self._ssh:
return tunnel.tunnel_connection(s, url, sshserver, **ssh_kwargs)
else:
return s.connect(url)
self.session.send(self._query_socket, 'connection_request')
# use Poller because zmq.select has wrong units in pyzmq 2.1.7
poller = zmq.Poller()
poller.register(self._query_socket, zmq.POLLIN)
# poll expects milliseconds, timeout is seconds
evts = poller.poll(timeout*1000)
if not evts:
raise error.TimeoutError("Hub connection request timed out")
idents,msg = self.session.recv(self._query_socket,mode=0)
if self.debug:
pprint(msg)
content = msg['content']
# self._config['registration'] = dict(content)
cfg = self._config
if content['status'] == 'ok':
self._mux_socket = self._context.socket(zmq.DEALER)
connect_socket(self._mux_socket, cfg['mux'])
self._task_socket = self._context.socket(zmq.DEALER)
connect_socket(self._task_socket, cfg['task'])
self._notification_socket = self._context.socket(zmq.SUB)
self._notification_socket.setsockopt(zmq.SUBSCRIBE, b'')
connect_socket(self._notification_socket, cfg['notification'])
self._control_socket = self._context.socket(zmq.DEALER)
connect_socket(self._control_socket, cfg['control'])
self._iopub_socket = self._context.socket(zmq.SUB)
self._iopub_socket.setsockopt(zmq.SUBSCRIBE, b'')
connect_socket(self._iopub_socket, cfg['iopub'])
self._update_engines(dict(content['engines']))
else:
self._connected = False
raise Exception("Failed to connect!")
#--------------------------------------------------------------------------
# handlers and callbacks for incoming messages
#--------------------------------------------------------------------------
开发者ID:ktraunmueller,项目名称:Computable,代码行数:57,代码来源:client.py示例10: resubmit
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import select [as 别名]
def resubmit(self, indices_or_msg_ids=None, metadata=None, block=None):
"""Resubmit one or more tasks.
in-flight tasks may not be resubmitted.
Parameters
----------
indices_or_msg_ids : integer history index, str msg_id, or list of either
The indices or msg_ids of indices to be retrieved
block : bool
Whether to wait for the result to be done
Returns
-------
AsyncHubResult
A subclass of AsyncResult that retrieves results from the Hub
"""
block = self.block if block is None else block
if indices_or_msg_ids is None:
indices_or_msg_ids = -1
if not isinstance(indices_or_msg_ids, (list,tuple)):
indices_or_msg_ids = [indices_or_msg_ids]
theids = []
for id in indices_or_msg_ids:
if isinstance(id, int):
id = self.history[id]
if not isinstance(id, basestring):
raise TypeError("indices must be str or int, not %r"%id)
theids.append(id)
content = dict(msg_ids = theids)
self.session.send(self._query_socket, 'resubmit_request', content)
zmq.select([self._query_socket], [], [])
idents,msg = self.session.recv(self._query_socket, zmq.NOBLOCK)
if self.debug:
pprint(msg)
content = msg['content']
if content['status'] != 'ok':
raise self._unwrap_exception(content)
mapping = content['resubmitted']
new_ids = [ mapping[msg_id] for msg_id in theids ]
ar = AsyncHubResult(self, msg_ids=new_ids)
if block:
ar.wait()
return ar
开发者ID:ktraunmueller,项目名称:Computable,代码行数:58,代码来源:client.py本文标签属性:
示例:示例的拼音
代码:代码转换器
Python:python怎么读
select:select翻译