本文整理汇总了Python中zmq.TYPE属性的典型用法代码示例。如果您正苦于以下问题:Python zmq.TYPE属性的具体用法?Python zmq.TYPE怎么用?Python zmq.TYPE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类zmq
的用法示例。
在下文中一共展示了zmq.TYPE属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_heartbeat
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import TYPE [as 别名]
def _do_heartbeat(self):
while True:
try:
if self._socket.getsockopt(zmq.TYPE) == zmq.ROUTER:
yield from self._do_router_heartbeat()
elif self._socket.getsockopt(zmq.TYPE) == zmq.DEALER:
yield from self._do_dealer_heartbeat()
yield from asyncio.sleep(self._heartbeat_interval,
loop=self._event_loop)
except CancelledError: # pylint: disable=try-except-raise
# The concurrent.futures.CancelledError is caught by asyncio
# when the Task associated with the coroutine is cancelled.
# The raise is required to stop this component.
raise
except Exception as e: # pylint: disable=broad-except
LOGGER.exception(
"An error occurred while sending heartbeat: %s", e)
示例2: _check_closed_deep
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import TYPE [as 别名]
def _check_closed_deep(self):
"""thorough check of whether the socket has been closed,
even if by another entity (e.g. ctx.destroy).
Only used by the `closed` property.
returns True if closed, False otherwise
"""
if self._closed:
return True
try:
self.get(zmq.TYPE)
except ZMQError as e:
if e.errno == zmq.ENOTSOCK:
self._closed = True
return True
else:
raise
return False
示例3: _receive_message
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import TYPE [as 别名]
def _receive_message(self):
"""
Internal coroutine for receiving messages
"""
while True:
try:
if self._socket.getsockopt(zmq.TYPE) == zmq.ROUTER:
zmq_identity, msg_bytes = \
yield from self._socket.recv_multipart()
if msg_bytes == b'':
# send ACK for connection probes
LOGGER.debug("ROUTER PROBE FROM %s", zmq_identity)
self._socket.send_multipart(
[bytes(zmq_identity), msg_bytes])
else:
self._received_from_identity(zmq_identity)
self._dispatcher_queue.put_nowait(
(zmq_identity, msg_bytes))
else:
msg_bytes = yield from self._socket.recv()
self._last_message_time = time.time()
self._dispatcher_queue.put_nowait((None, msg_bytes))
self._get_queue_size_gauge(self.connection).set_value(
self._dispatcher_queue.qsize())
except CancelledError: # pylint: disable=try-except-raise
# The concurrent.futures.CancelledError is caught by asyncio
# when the Task associated with the coroutine is cancelled.
# The raise is required to stop this component.
raise
except Exception as e: # pylint: disable=broad-except
LOGGER.exception("Received a message on address %s that "
"caused an error: %s", self._address, e)
示例4: check_socket
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import TYPE [as 别名]
def check_socket(socket, socket_type, bind_address):
"""check if the given socket is open, binded to the correct address and have
the correct type
"""
assert isinstance(socket, zmq.Socket)
assert socket.closed is False
assert socket.get(zmq.TYPE) == socket_type
socket_address = socket.get(zmq.LAST_ENDPOINT).decode("utf-8")
assert socket_address == bind_address
示例5: test_int_sockopts
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import TYPE [as 别名]
def test_int_sockopts(self):
"test integer sockopts"
v = zmq.zmq_version_info()
if v < (3,0):
default_hwm = 0
else:
default_hwm = 1000
p,s = self.create_bound_pair(zmq.PUB, zmq.SUB)
p.setsockopt(zmq.LINGER, 0)
self.assertEqual(p.getsockopt(zmq.LINGER), 0)
p.setsockopt(zmq.LINGER, -1)
self.assertEqual(p.getsockopt(zmq.LINGER), -1)
self.assertEqual(p.hwm, default_hwm)
p.hwm = 11
self.assertEqual(p.hwm, 11)
# p.setsockopt(zmq.EVENTS, zmq.POLLIN)
self.assertEqual(p.getsockopt(zmq.EVENTS), zmq.POLLOUT)
self.assertRaisesErrno(zmq.EINVAL, p.setsockopt,zmq.EVENTS, 2**7-1)
self.assertEqual(p.getsockopt(zmq.TYPE), p.socket_type)
self.assertEqual(p.getsockopt(zmq.TYPE), zmq.PUB)
self.assertEqual(s.getsockopt(zmq.TYPE), s.socket_type)
self.assertEqual(s.getsockopt(zmq.TYPE), zmq.SUB)
# check for overflow / wrong type:
errors = []
backref = {}
constants = zmq.constants
for name in constants.__all__:
value = getattr(constants, name)
if isinstance(value, int):
backref[value] = name
for opt in zmq.constants.int_sockopts.union(zmq.constants.int64_sockopts):
sopt = backref[opt]
if sopt.startswith((
'ROUTER', 'XPUB', 'TCP', 'FAIL',
'REQ_', 'CURVE_', 'PROBE_ROUTER',
'IPC_FILTER', 'GSSAPI', 'STREAM_',
'VMCI_BUFFER_SIZE', 'VMCI_BUFFER_MIN_SIZE',
'VMCI_BUFFER_MAX_SIZE', 'VMCI_CONNECT_TIMEOUT',
)):
# some sockopts are write-only
continue
try:
n = p.getsockopt(opt)
except zmq.ZMQError as e:
errors.append("getsockopt(zmq.%s) raised '%s'."%(sopt, e))
else:
if n > 2**31:
errors.append("getsockopt(zmq.%s) returned a ridiculous value."
" It is probably the wrong type."%sopt)
if errors:
self.fail('\n'.join([''] + errors))