本文整理汇总了Python中zmq.POLLERR属性的典型用法代码示例。如果您正苦于以下问题:Python zmq.POLLERR属性的具体用法?Python zmq.POLLERR怎么用?Python zmq.POLLERR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类zmq
的用法示例。
在下文中一共展示了zmq.POLLERR属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_descriptors
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLERR [as 别名]
def _get_descriptors(self):
"""Returns three elements tuple with socket descriptors ready
for gevent.select.select
"""
rlist = []
wlist = []
xlist = []
for socket, flags in self.sockets:
if isinstance(socket, zmq.Socket):
rlist.append(socket.getsockopt(zmq.FD))
continue
elif isinstance(socket, int):
fd = socket
elif hasattr(socket, 'fileno'):
try:
fd = int(socket.fileno())
except:
raise ValueError('fileno() must return an valid integer fd')
else:
raise TypeError('Socket must be a 0MQ socket, an integer fd '
'or have a fileno() method: %r' % socket)
if flags & zmq.POLLIN:
rlist.append(fd)
if flags & zmq.POLLOUT:
wlist.append(fd)
if flags & zmq.POLLERR:
xlist.append(fd)
return (rlist, wlist, xlist)
示例2: console_messages
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLERR [as 别名]
def console_messages(ws):
"""Receive console messages as they happen
ZMQ message format:
Console messages:
console cluster_name {"job_id":"current_job_id", "msg":"message from console"}
Control messages:
Keep alive:
The cluster is starting a job:
console cluster_name {"job_id":"current_job_id", "ctl":"START"}
The cluster finished a job:
console cluster_name {"job_id":"current_job_id", "ctl":"DONE"}
The cluster is not working on anything:
console cluster_name {"ctl":"IDLE"}
When forwarding messages to the websocket client, the "console cluster_name"
portion is dropped and just the JSON is sent.
Websocket sends keepalive messages periodically:
{"ctl":"KEEPALIVE"}
"""
cluster_name = ws.receive()
console_socket = console_subscribe(cluster_name)
try:
while True:
try:
data = console_socket.recv_string()
data = data.lstrip("console {cluster_name} ".format(cluster_name=cluster_name))
ws.send(data)
except zmq.error.Again:
# If we timeout from zmq, send a keep alive request to the
# websocket client:
ws.send('{"ctl":"KEEPALIVE"}')
# The client websocket will send keepalive back:
ws.receive()
except zmq.error.ZMQError, e:
if e.errno == zmq.POLLERR:
log.error(e)
# Interrupted zmq socket code, reinitialize:
# I get this when I resize my terminal.. WTF?
console_socket = setup_zmq()
finally:
log.error("Unsubscribing from zmq socket")
console_socket.setsockopt_string(zmq.UNSUBSCRIBE, u'')