本文整理汇总了Python中zmq.ZMQError方法的典型用法代码示例。如果您正苦于以下问题:Python zmq.ZMQError方法的具体用法?Python zmq.ZMQError怎么用?Python zmq.ZMQError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmq
的用法示例。
在下文中一共展示了zmq.ZMQError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def start(self):
"""Starts receiving messages on the underlying socket and passes them
to the message router.
"""
self._is_running = True
while self._is_running:
try:
zmq_msg = await self._socket.recv_multipart()
message = Message()
message.ParseFromString(zmq_msg[-1])
await self._msg_router.route_msg(message)
except DecodeError as e:
LOGGER.warning('Unable to decode: %s', e)
except zmq.ZMQError as e:
LOGGER.warning('Unable to receive: %s', e)
return
except asyncio.CancelledError:
self._is_running = False
示例2: run
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def run(self):
"""Start the Authentication Agent thread task"""
self.authenticator.start()
self.started.set()
zap = self.authenticator.zap_socket
poller = zmq.Poller()
poller.register(self.pipe, zmq.POLLIN)
poller.register(zap, zmq.POLLIN)
while True:
try:
socks = dict(poller.poll())
except zmq.ZMQError:
break # interrupted
if self.pipe in socks and socks[self.pipe] == zmq.POLLIN:
terminate = self._handle_pipe()
if terminate:
break
if zap in socks and socks[zap] == zmq.POLLIN:
self._handle_zap()
self.pipe.close()
self.authenticator.stop()
示例3: get_hwm
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def get_hwm(self):
"""Get the High Water Mark.
On libzmq ≥ 3, this gets SNDHWM if available, otherwise RCVHWM
"""
major = zmq.zmq_version_info()[0]
if major >= 3:
# return sndhwm, fallback on rcvhwm
try:
return self.getsockopt(zmq.SNDHWM)
except zmq.ZMQError:
pass
return self.getsockopt(zmq.RCVHWM)
else:
return self.getsockopt(zmq.HWM)
示例4: recv_string
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def recv_string(self, flags=0, encoding='utf-8'):
"""Receive a unicode string, as sent by send_string.
Parameters
----------
flags : int
Any valid flags for :func:`Socket.recv`.
encoding : str [default: 'utf-8']
The encoding to be used
Returns
-------
s : unicode string (unicode on py2, str on py3)
The Python unicode string that arrives as encoded bytes.
Raises
------
ZMQError
for any of the reasons :func:`~Socket.recv` might fail
"""
msg = self.recv(flags=flags)
return self._deserialize(msg, lambda buf: buf.decode(encoding))
示例5: recv_pyobj
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def recv_pyobj(self, flags=0):
"""Receive a Python object as a message using pickle to serialize.
Parameters
----------
flags : int
Any valid flags for :func:`Socket.recv`.
Returns
-------
obj : Python object
The Python object that arrives as a message.
Raises
------
ZMQError
for any of the reasons :func:`~Socket.recv` might fail
"""
msg = self.recv(flags)
return self._deserialize(msg, pickle.loads)
示例6: recv_json
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def recv_json(self, flags=0, **kwargs):
"""Receive a Python object as a message using json to serialize.
Keyword arguments are passed on to json.loads
Parameters
----------
flags : int
Any valid flags for :func:`Socket.recv`.
Returns
-------
obj : Python object
The Python object that arrives as a message.
Raises
------
ZMQError
for any of the reasons :func:`~Socket.recv` might fail
"""
from zmq.utils import jsonapi
msg = self.recv(flags)
return self._deserialize(msg, lambda buf: jsonapi.loads(buf, **kwargs))
示例7: _handle_recv
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def _handle_recv(self):
"""Handle a recv event."""
if self._flushed:
return
try:
msg = self.socket.recv_multipart(zmq.NOBLOCK, copy=self._recv_copy)
except zmq.ZMQError as e:
if e.errno == zmq.EAGAIN:
# state changed since poll event
pass
else:
raise
else:
if self._recv_callback:
callback = self._recv_callback
self._run_callback(callback, msg)
示例8: build_device
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def build_device(self, mon_sub=b"", in_prefix=b'in', out_prefix=b'out'):
self.device = devices.ThreadMonitoredQueue(zmq.PAIR, zmq.PAIR, zmq.PUB,
in_prefix, out_prefix)
alice = self.context.socket(zmq.PAIR)
bob = self.context.socket(zmq.PAIR)
mon = self.context.socket(zmq.SUB)
aport = alice.bind_to_random_port('tcp://127.0.0.1')
bport = bob.bind_to_random_port('tcp://127.0.0.1')
mport = mon.bind_to_random_port('tcp://127.0.0.1')
mon.setsockopt(zmq.SUBSCRIBE, mon_sub)
self.device.connect_in("tcp://127.0.0.1:%i"%aport)
self.device.connect_out("tcp://127.0.0.1:%i"%bport)
self.device.connect_mon("tcp://127.0.0.1:%i"%mport)
self.device.start()
time.sleep(.2)
try:
# this is currenlty necessary to ensure no dropped monitor messages
# see LIBZMQ-248 for more info
mon.recv_multipart(zmq.NOBLOCK)
except zmq.ZMQError:
pass
self.sockets.extend([alice, bob, mon])
return alice, bob, mon
示例9: _receiveFromListener
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def _receiveFromListener(self, quota: Quota) -> int:
"""
Receives messages from listener
:param quota: number of messages to receive
:return: number of received messages
"""
i = 0
incoming_size = 0
try:
ident, msg = self.listener.recv_multipart(flags=zmq.NOBLOCK)
if msg:
# Router probing sends empty message on connection
incoming_size += len(msg)
i += 1
self._verifyAndAppend(msg, ident)
except zmq.Again as e:
return i
except zmq.ZMQError as e:
print("Strange ZMQ behaviour during node-to-node message receiving, experienced {}".format(e))
if i > 0:
print('{} got {} messages through listener'.
format(self, i))
return i
示例10: _bind_with_timeout
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def _bind_with_timeout(bind_function, args, n_tries=3, retry_interval_s=0.5):
"""Attempt to bind a socket a number of times with a short interval in between
Especially on Linux, crashing out of a networkzero process can leave the sockets
lingering and unable to re-bind on startup. We give it a few goes here to see if
we can bind within a couple of seconds.
"""
n_tries_left = n_tries
while n_tries_left > 0:
try:
return bind_function(*args)
except zmq.error.ZMQError as exc:
_logger.warn("%s; %d tries remaining", exc, n_tries_left)
n_tries_left -= 1
except OSError as exc:
if exc.errno == errno.EADDRINUSE:
_logger.warn("%s; %d tries remaining", exc, n_tries_left)
n_tries_left -= 1
else:
raise
else:
raise core.SocketAlreadyExistsError("Failed to bind after %s tries" % n_tries)
示例11: poll_command_request
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def poll_command_request(self):
"""If the command RPC socket has an incoming request,
separate it into its action and its params and put it
on the command request queue.
"""
try:
message = self.rpc.recv(zmq.NOBLOCK)
except zmq.ZMQError as exc:
if exc.errno == zmq.EAGAIN:
return
else:
raise
_logger.debug("Received command %s", message)
segments = _unpack(message)
action, params = segments[0], segments[1:]
_logger.debug("Adding %s, %s to the request queue", action, params)
self._command = _Command(action, params)
示例12: get_command
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def get_command(self):
"""Attempt to return a unicode object from the command socket
If no message is available without blocking (as opposed to a blank
message), return None
"""
try:
message_bytes = self.socket.recv(zmq.NOBLOCK)
log.debug("Received message: %r", message_bytes)
except zmq.ZMQError as exc:
if exc.errno == zmq.EAGAIN:
return None
else:
raise
else:
return message_bytes.decode(config.CODEC)
示例13: get_hwm
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def get_hwm(self):
"""get the High Water Mark
On libzmq ≥ 3, this gets SNDHWM if available, otherwise RCVHWM
"""
major = zmq.zmq_version_info()[0]
if major >= 3:
# return sndhwm, fallback on rcvhwm
try:
return self.getsockopt(zmq.SNDHWM)
except zmq.ZMQError as e:
pass
return self.getsockopt(zmq.RCVHWM)
else:
return self.getsockopt(zmq.HWM)
示例14: _handle_recv
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def _handle_recv(self):
"""Handle a recv event."""
if self._flushed:
return
try:
msg = self.socket.recv_multipart(zmq.NOBLOCK, copy=self._recv_copy)
except zmq.ZMQError as e:
if e.errno == zmq.EAGAIN:
# state changed since poll event
pass
else:
gen_log.error("RECV Error: %s"%zmq.strerror(e.errno))
else:
if self._recv_callback:
callback = self._recv_callback
# self._recv_callback = None
self._run_callback(callback, msg)
# self.update_state()
示例15: _run_loop
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ZMQError [as 别名]
def _run_loop(self):
"""Run my loop, ignoring EINTR events in the poller"""
while True:
try:
self.ioloop.start()
except ZMQError as e:
if e.errno == errno.EINTR:
continue
else:
raise
except Exception:
if self._exiting:
break
else:
raise
else:
break