本文整理汇总了Python中zmq.PULL属性的典型用法代码示例。如果您正苦于以下问题:Python zmq.PULL属性的具体用法?Python zmq.PULL怎么用?Python zmq.PULL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类zmq
的用法示例。
在下文中一共展示了zmq.PULL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def run(self):
enable_death_signal(_warn=self.identity == b'0')
ctx = zmq.Context()
# recv jobs
socket = ctx.socket(zmq.PULL)
socket.setsockopt(zmq.IDENTITY, self.identity)
socket.set_hwm(self.hwm * self.batch_size)
socket.connect(self.input_pipe)
# send results
out_socket = ctx.socket(zmq.PUSH)
out_socket.set_hwm(max(self.hwm, 5))
out_socket.connect(self.result_pipe)
batch = []
while True:
dp = loads(socket.recv(copy=False))
dp = self.map_func(dp)
if dp is not None:
batch.append(dp)
if len(batch) == self.batch_size:
dp = BatchData.aggregate_batch(batch)
out_socket.send(dumps(dp), copy=False)
del batch[:]
示例2: reset_state
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def reset_state(self):
_MultiProcessZMQDataFlow.reset_state(self)
self._guard = DataFlowReentrantGuard()
job_pipe = _get_pipe_name("dataflow_MaB_job")
result_pipe = _get_pipe_name("dataflow_MaB_result")
self.context = zmq.Context()
self.socket = self.context.socket(zmq.PULL)
self.socket.set_hwm(max(5, self.buffer_size // self.batch_size))
_bind_guard(self.socket, result_pipe)
dispatcher = MultiProcessMapAndBatchDataZMQ._Dispatcher(self.ds, job_pipe, self.buffer_size)
self._proc_ids = [u'{}'.format(k).encode('utf-8') for k in range(self.num_proc)]
worker_hwm = max(3, self.buffer_size // self.num_proc // self.batch_size)
self._procs = [MultiProcessMapAndBatchDataZMQ._Worker(
self._proc_ids[k], self.map_func, job_pipe, result_pipe, worker_hwm, self.batch_size)
for k in range(self.num_proc)]
self._procs.append(dispatcher)
self._start_processes()
示例3: run
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def run(self):
context = zmq.Context()
receiver = context.socket(zmq.PULL)
receiver.connect(self.worker_address)
sink = context.socket(zmq.PUSH)
sink.connect(self.sink_address)
input_fn = self.input_fn_builder(receiver)
self.logger.info('ready and listening')
start_t = time.perf_counter()
for r in self.estimator.predict(input_fn, yield_single_examples=False):
# logger.info('new result!')
send_ndarray(sink, r['client_id'], r['encodes'])
time_used = time.perf_counter() - start_t
start_t = time.perf_counter()
self.logger.info('job %s\tsamples: %4d\tdone: %.2fs' %
(r['client_id'], r['encodes'].shape[0], time_used))
receiver.close()
sink.close()
context.term()
self.logger.info('terminated!')
示例4: test_shadow_pyczmq
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def test_shadow_pyczmq(self):
try:
from pyczmq import zctx, zsocket
except Exception:
raise SkipTest("Requires pyczmq")
ctx = zctx.new()
ca = zsocket.new(ctx, zmq.PUSH)
cb = zsocket.new(ctx, zmq.PULL)
a = zmq.Socket.shadow(ca)
b = zmq.Socket.shadow(cb)
a.bind("inproc://a")
b.connect("inproc://a")
a.send(b'hi')
rcvd = self.recv(b)
self.assertEqual(rcvd, b'hi')
示例5: test_recv_json_cancelled
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def test_recv_json_cancelled(self):
@asyncio.coroutine
def test():
a, b = self.create_bound_pair(zmq.PUSH, zmq.PULL)
f = b.recv_json()
assert not f.done()
f.cancel()
# cycle eventloop to allow cancel events to fire
yield from asyncio.sleep(0)
obj = dict(a=5)
yield from a.send_json(obj)
with pytest.raises(CancelledError):
recvd = yield from f
assert f.done()
# give it a chance to incorrectly consume the event
events = yield from b.poll(timeout=5)
assert events
yield from asyncio.sleep(0)
# make sure cancelled recv didn't eat up event
f = b.recv_json()
recvd = yield from asyncio.wait_for(f, timeout=5)
assert recvd == obj
self.loop.run_until_complete(test())
示例6: test_poll
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def test_poll(self):
@asyncio.coroutine
def test():
a, b = self.create_bound_pair(zmq.PUSH, zmq.PULL)
f = b.poll(timeout=0)
yield from asyncio.sleep(0)
self.assertEqual(f.result(), 0)
f = b.poll(timeout=1)
assert not f.done()
evt = yield from f
self.assertEqual(evt, 0)
f = b.poll(timeout=1000)
assert not f.done()
yield from a.send_multipart([b'hi', b'there'])
evt = yield from f
self.assertEqual(evt, zmq.POLLIN)
recvd = yield from b.recv_multipart()
self.assertEqual(recvd, [b'hi', b'there'])
self.loop.run_until_complete(test())
示例7: test_poll_base_socket
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def test_poll_base_socket(self):
@asyncio.coroutine
def test():
ctx = zmq.Context()
url = 'inproc://test'
a = ctx.socket(zmq.PUSH)
b = ctx.socket(zmq.PULL)
self.sockets.extend([a, b])
a.bind(url)
b.connect(url)
poller = zaio.Poller()
poller.register(b, zmq.POLLIN)
f = poller.poll(timeout=1000)
assert not f.done()
a.send_multipart([b'hi', b'there'])
evt = yield from f
self.assertEqual(evt, [(b, zmq.POLLIN)])
recvd = b.recv_multipart()
self.assertEqual(recvd, [b'hi', b'there'])
self.loop.run_until_complete(test())
示例8: test_cyclic_destroy
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def test_cyclic_destroy(self):
"""ctx.destroy should succeed when cyclic ref prevents gc"""
# test credit @dln (GH #137):
class CyclicReference(object):
def __init__(self, parent=None):
self.parent = parent
def crash(self, sock):
self.sock = sock
self.child = CyclicReference(self)
def crash_zmq():
ctx = self.Context()
sock = ctx.socket(zmq.PULL)
c = CyclicReference()
c.crash(sock)
ctx.destroy()
crash_zmq()
示例9: test_shadow_pyczmq
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def test_shadow_pyczmq(self):
try:
from pyczmq import zctx, zsocket, zstr
except Exception:
raise SkipTest("Requires pyczmq")
ctx = zctx.new()
a = zsocket.new(ctx, zmq.PUSH)
zsocket.bind(a, "inproc://a")
ctx2 = self.Context.shadow_pyczmq(ctx)
b = ctx2.socket(zmq.PULL)
b.connect("inproc://a")
zstr.send(a, b'hi')
rcvd = self.recv(b)
self.assertEqual(rcvd, b'hi')
b.close()
示例10: test_recv_json_cancelled
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def test_recv_json_cancelled(self):
@gen.coroutine
def test():
a, b = self.create_bound_pair(zmq.PUSH, zmq.PULL)
f = b.recv_json()
assert not f.done()
f.cancel()
# cycle eventloop to allow cancel events to fire
yield gen.sleep(0)
obj = dict(a=5)
yield a.send_json(obj)
with pytest.raises(future.CancelledError):
recvd = yield f
assert f.done()
# give it a chance to incorrectly consume the event
events = yield b.poll(timeout=5)
assert events
yield gen.sleep(0)
# make sure cancelled recv didn't eat up event
recvd = yield gen.with_timeout(timedelta(seconds=5), b.recv_json())
assert recvd == obj
self.loop.run_sync(test)
示例11: test_poll
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def test_poll(self):
@gen.coroutine
def test():
a, b = self.create_bound_pair(zmq.PUSH, zmq.PULL)
f = b.poll(timeout=0)
assert f.done()
self.assertEqual(f.result(), 0)
f = b.poll(timeout=1)
assert not f.done()
evt = yield f
self.assertEqual(evt, 0)
f = b.poll(timeout=1000)
assert not f.done()
yield a.send_multipart([b'hi', b'there'])
evt = yield f
self.assertEqual(evt, zmq.POLLIN)
recvd = yield b.recv_multipart()
self.assertEqual(recvd, [b'hi', b'there'])
self.loop.run_sync(test)
示例12: test_poll_base_socket
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def test_poll_base_socket(self):
@gen.coroutine
def test():
ctx = zmq.Context()
url = 'inproc://test'
a = ctx.socket(zmq.PUSH)
b = ctx.socket(zmq.PULL)
self.sockets.extend([a, b])
a.bind(url)
b.connect(url)
poller = future.Poller()
poller.register(b, zmq.POLLIN)
f = poller.poll(timeout=1000)
assert not f.done()
a.send_multipart([b'hi', b'there'])
evt = yield f
self.assertEqual(evt, [(b, zmq.POLLIN)])
recvd = b.recv_multipart()
self.assertEqual(recvd, [b'hi', b'there'])
a.close()
b.close()
ctx.term()
self.loop.run_sync(test)
示例13: remote_recv
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def remote_recv(self, _socket):
if self._PULL_SOCKET_STATUS['state'] == True:
try:
msg = _socket.recv_string(zmq.DONTWAIT)
return msg
except zmq.error.Again:
print("\nResource timeout.. please try again.")
sleep(self._sleep_delay)
else:
print('\r[KERNEL] NO HANDSHAKE ON PULL SOCKET.. Cannot READ data', end='', flush=True)
return None
##########################################################################
# Convenience functions to permit easy trading via underlying functions.
# OPEN ORDER
示例14: run
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def run(self):
s = self.gc.context.socket(zmq.PULL)
s.linger = 0
s.bind(self.gc.url)
self.ready.set()
while True:
# detect fork
if getpid is None or getpid() != self.pid:
return
msg = s.recv()
if msg == b'DIE':
break
fmt = 'L' if len(msg) == 4 else 'Q'
key = struct.unpack(fmt, msg)[0]
tup = self.gc.refs.pop(key, None)
if tup and tup.event:
tup.event.set()
del tup
s.close()
示例15: forward_read_events
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PULL [as 别名]
def forward_read_events(fd, context=None):
"""Forward read events from an FD over a socket.
This method wraps a file in a socket pair, so it can
be polled for read events by select (specifically zmq.eventloop.ioloop)
"""
if context is None:
context = zmq.Context.instance()
push = context.socket(zmq.PUSH)
push.setsockopt(zmq.LINGER, -1)
pull = context.socket(zmq.PULL)
addr='inproc://%s'%uuid.uuid4()
push.bind(addr)
pull.connect(addr)
forwarder = ForwarderThread(push, fd)
forwarder.start()
return pull