本文整理汇总了Python中zmq.ContextTerminated方法的典型用法代码示例。如果您正苦于以下问题:Python zmq.ContextTerminated方法的具体用法?Python zmq.ContextTerminated怎么用?Python zmq.ContextTerminated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmq
的用法示例。
在下文中一共展示了zmq.ContextTerminated方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mainloop_recv
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ContextTerminated [as 别名]
def mainloop_recv(self):
try:
while True:
if self._frsock.closed:
break
msg = loadb(self._frsock.recv(copy=False).bytes)
identifier, type, payload = msg
self._dispatcher.dispatch(type, self, identifier, payload)
except zmq.ContextTerminated:
pass
except zmq.ZMQError as e:
if self._tosock.closed:
logger.warning('Recv socket closed unexpectedly.')
else:
raise e
示例2: run
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ContextTerminated [as 别名]
def run(self):
context = zmq.Context()
frontend = context.socket(zmq.ROUTER)
frontend.bind('tcp://*:5570')
backend = context.socket(zmq.DEALER)
backend.bind('inproc://backend')
worker = ParameterWorker(context)
worker.start()
try:
zmq.proxy(frontend, backend)
except zmq.ContextTerminated:
frontend.close()
backend.close()
示例3: _zmq_catch_error
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ContextTerminated [as 别名]
def _zmq_catch_error(name):
try:
yield
except zmq.ContextTerminated:
logger.info("[{}] Context terminated.".format(name))
raise DataFlowTerminated()
except zmq.ZMQError as e:
if e.errno == errno.ENOTSOCK: # socket closed
logger.info("[{}] Socket closed.".format(name))
raise DataFlowTerminated()
else:
raise
except Exception:
raise
示例4: receive_message
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ContextTerminated [as 别名]
def receive_message(socket, blocking=True):
flags = 0 if blocking else zmq.NOBLOCK
try:
cmd, data = socket.recv_multipart(flags=flags)
return cmd, data
except zmq.Again:
return None, None
except zmq.ContextTerminated:
print("Context terminated ..")
return None, None
except KeyboardInterrupt:
return None, None
示例5: atest_ctxterm
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ContextTerminated [as 别名]
def atest_ctxterm(self):
s = self.context.socket(zmq.REP)
t = Thread(target=self.context.term)
t.start()
self.assertRaises(ContextTerminated, s.recv, zmq.NOBLOCK)
self.assertRaisesErrno(zmq.TERM, s.recv, zmq.NOBLOCK)
s.close()
t.join()
示例6: _zmq_catch_error
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ContextTerminated [as 别名]
def _zmq_catch_error(name):
try:
yield
except zmq.ContextTerminated:
print("[{}] Context terminated.".format(name))
raise Exception
except zmq.ZMQError as e:
if e.errno == errno.ENOTSOCK: # socket closed
print("[{}] Socket closed.".format(name))
raise Exception
else:
raise
except Exception:
raise
示例7: mainloop_send
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ContextTerminated [as 别名]
def mainloop_send(self):
try:
while True:
if self._tosock.closed:
break
job = self._send_queue.get()
self._tosock.send_multipart([job.identifier, dumpb(job.payload)], copy=False)
except zmq.ContextTerminated:
pass
except zmq.ZMQError as e:
if self._tosock.closed:
logger.warning('Send socket closed unexpectedly.')
else:
raise e
示例8: recv
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ContextTerminated [as 别名]
def recv(self):
try:
return loadb(self._sock.recv(copy=False).bytes)
except zmq.ContextTerminated:
pass
示例9: mainloop_send
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ContextTerminated [as 别名]
def mainloop_send(self):
try:
while True:
job = self._send_queue.get()
self._sock.send(dumpb(job), copy=False)
except zmq.ContextTerminated:
pass
示例10: run
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import ContextTerminated [as 别名]
def run(self):
self.clients = defaultdict(self.ClientState)
try:
while True:
msg = loads(self.c2s_socket.recv(copy=False))
ident, state, reward, isOver = msg
client = self.clients[ident]
if client.ident is None:
client.ident = ident
# maybe check history and warn about dead client?
self._process_msg(client, state, reward, isOver)
except zmq.ContextTerminated:
logger.info("[Simulator] Context was terminated.")