本文整理汇总了Python中zmq.green.Context方法的典型用法代码示例。如果您正苦于以下问题:Python green.Context方法的具体用法?Python green.Context怎么用?Python green.Context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmq.green
的用法示例。
在下文中一共展示了green.Context方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_monitor
# 需要导入模块: from zmq import green [as 别名]
# 或者: from zmq.green import Context [as 别名]
def create_monitor(address, socketio):
def create_poller():
context = zmq.Context()
socket = context.socket(zmq.PULL)
socket.bind(address)
sockets = {
"master": {"socket": socket, "receive": socket.recv, "send": socket.send},
}
time_func = time.time
return Poller(sockets, time_func)
def emit(message):
socketio.emit("status_update", message)
scale_workers = lambda command: True
run_forever = lambda: True
return Monitor(create_poller, emit, scale_workers, run_forever)
示例2: start
# 需要导入模块: from zmq import green [as 别名]
# 或者: from zmq.green import Context [as 别名]
def start(self, start_dispatching=True):
self.context = zmq.Context()
for rfcc in self.rpc_fanout_clients_channels:
rfcc.connect(self.context)
for rpcc in self.rpc_server_channels.values():
rpcc.connect(self.context)
for sc in self.sub_channels:
sc.connect()
for mwsc in self.mw_sub_channels:
mwsc.connect(self.context)
for pc in self.pub_channels:
pc.connect()
for mwpc in self.mw_pub_channels:
mwpc.connect(self.context)
if start_dispatching:
self.start_dispatching()
示例3: tearDown
# 需要导入模块: from zmq import green [as 别名]
# 或者: from zmq.green import Context [as 别名]
def tearDown(self):
contexts = set([self.context])
while self.sockets:
sock = self.sockets.pop()
contexts.add(sock.context) # in case additional contexts are created
sock.close(0)
for ctx in contexts:
t = Thread(target=ctx.term)
t.daemon = True
t.start()
t.join(timeout=2)
if t.is_alive():
# reset Context.instance, so the failure to term doesn't corrupt subsequent tests
zmq.sugar.context.Context._instance = None
raise RuntimeError("context could not terminate, open sockets likely remain in test")
super(BaseZMQTestCase, self).tearDown()
示例4: init
# 需要导入模块: from zmq import green [as 别名]
# 或者: from zmq.green import Context [as 别名]
def init(self):
self.log.debug("init zeromq ..")
if not zmq:
self.log.critical("missing zeromq, please install pyzmq to use this plugin")
raise RuntimeError("zeromq python module not found")
self.ctx = zmq.Context()
# sanity check config
if 'bind' in self.config:
if 'connect' in self.config:
msg = "bind and connect are mutually exclusive"
self.log.critical(msg)
raise ValueError(msg)
elif 'connect' not in self.config:
msg = "missing bind or connect"
self.log.critical(msg)
raise ValueError(msg)
示例5: setUp
# 需要导入模块: from zmq import green [as 别名]
# 或者: from zmq.green import Context [as 别名]
def setUp(self):
context = zmq.Context()
worker_socket = context.socket(zmq.REP)
worker_socket.bind("ipc:///tmp/worker")
frontend_socket = context.socket(zmq.REP)
frontend_socket.bind("ipc:///tmp/frontend")
sockets = {
"worker": {"socket": worker_socket, "receive": worker_socket.recv_json, "send": worker_socket.send_json},
"frontend": {"socket": frontend_socket, "receive": frontend_socket.recv_json, "send": worker_socket.send_json},
}
time = TimeStub()
self.poller = Poller(sockets, time)
示例6: send_message
# 需要导入模块: from zmq import green [as 别名]
# 或者: from zmq.green import Context [as 别名]
def send_message(self, address, message):
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect(address)
socket.send_json(message)
import gevent
gevent.sleep(0.05)
return socket
示例7: create_frontend_worker
# 需要导入模块: from zmq import green [as 别名]
# 或者: from zmq.green import Context [as 别名]
def create_frontend_worker(master_address):
context = zmq.Context()
master_socket = context.socket(zmq.REQ)
master_socket.connect(master_address)
worker_socket = context.socket(zmq.REQ)
decoder = Decoder()
id_generator = lambda: uuid.uuid4().int
return FrontendWorker(master_socket, worker_socket, decoder, id_generator)
示例8: create_recordings_saver
# 需要导入模块: from zmq import green [as 别名]
# 或者: from zmq.green import Context [as 别名]
def create_recordings_saver(address, model):
def create_socket():
context = zmq.Context()
socket = context.socket(zmq.PULL)
socket.bind(address)
return socket
run_forever = lambda: True
return RecordingsSaver(create_socket, model, run_forever)
示例9: context
# 需要导入模块: from zmq import green [as 别名]
# 或者: from zmq.green import Context [as 别名]
def context(self):
if self._context is None:
if Thread.__module__.startswith('gevent'):
# gevent has monkey-patched Thread, use green Context
from zmq import green
self._context = green.Context()
else:
self._context = zmq.Context()
return self._context
示例10: start
# 需要导入模块: from zmq import green [as 别名]
# 或者: from zmq.green import Context [as 别名]
def start(self):
"""Start a new garbage collection thread.
Creates a new zmq Context used for garbage collection.
Under most circumstances, this will only be called once per process.
"""
if self.thread is not None and self.pid != getpid():
# It's re-starting, must free earlier thread's context
# since a fork probably broke it
self._stop()
self.pid = getpid()
self.refs = {}
self.thread = GarbageCollectorThread(self)
self.thread.start()
self.thread.ready.wait()
示例11: Context
# 需要导入模块: from zmq import green [as 别名]
# 或者: from zmq.green import Context [as 别名]
def Context(self):
if self.green:
return gzmq.Context
else:
return zmq.Context
示例12: setUp
# 需要导入模块: from zmq import green [as 别名]
# 或者: from zmq.green import Context [as 别名]
def setUp(self):
super(BaseZMQTestCase, self).setUp()
if self.green and not have_gevent:
raise SkipTest("requires gevent")
self.context = self.Context.instance()
self.sockets = []
示例13: __init__
# 需要导入模块: from zmq import green [as 别名]
# 或者: from zmq.green import Context [as 别名]
def __init__(self):
self.context = zmq.Context()
self.XSUB_URL = ait.config.get('server.xsub',
ait.SERVER_DEFAULT_XSUB_URL)
self.XPUB_URL = ait.config.get('server.xpub',
ait.SERVER_DEFAULT_XPUB_URL)
## Name of the topic associated with external commands
self.command_topic = ait.config.get('command.topic',
ait.DEFAULT_CMD_TOPIC)
gevent.Greenlet.__init__(self)