本文整理汇总了Python中zmq.PUB属性的典型用法代码示例。如果您正苦于以下问题:Python zmq.PUB属性的具体用法?Python zmq.PUB怎么用?Python zmq.PUB使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类zmq
的用法示例。
在下文中一共展示了zmq.PUB属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def setUp(self):
super(TestZMQWorkerBasic,self).setUp()
self.rr_endpoint = self.make_endpoint()
self.ann_endpoint = self.make_endpoint()
# Need to bind ann_socket here in setup, because if we bind it during
# tests, messages get lost.
self.ann_socket = self.test_context.socket(zmq.PUB)
self.ann_socket.bind(self.ann_endpoint)
# If we're binding ann_socket, we might as well bind rr_socket
self.rr_socket = self.test_context.socket(zmq.REP)
self.rr_socket.bind(self.rr_endpoint)
self.test_worker = ZMQWorker(self.rr_endpoint, self.ann_endpoint)
self.test_worker.validation_fail_action = 'raise'
self.test_worker.shutdown_timeout = 0.5
self.test_worker.master_beacon_period = BEACON_PERIOD
self.test_worker.startup()
self.test_core.master_id = self.test_core.node_id
time.sleep(SETUP_WAIT)
示例2: test_unicode_sockopts
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def test_unicode_sockopts(self):
"""test setting/getting sockopts with unicode strings"""
topic = "tést"
if str is not unicode:
topic = topic.decode('utf8')
p,s = self.create_bound_pair(zmq.PUB, zmq.SUB)
self.assertEqual(s.send_unicode, s.send_unicode)
self.assertEqual(p.recv_unicode, p.recv_unicode)
self.assertRaises(TypeError, s.setsockopt, zmq.SUBSCRIBE, topic)
self.assertRaises(TypeError, s.setsockopt, zmq.IDENTITY, topic)
s.setsockopt_unicode(zmq.IDENTITY, topic, 'utf16')
self.assertRaises(TypeError, s.setsockopt, zmq.AFFINITY, topic)
s.setsockopt_unicode(zmq.SUBSCRIBE, topic)
self.assertRaises(TypeError, s.getsockopt_unicode, zmq.AFFINITY)
self.assertRaisesErrno(zmq.EINVAL, s.getsockopt_unicode, zmq.SUBSCRIBE)
identb = s.getsockopt(zmq.IDENTITY)
identu = identb.decode('utf16')
identu2 = s.getsockopt_unicode(zmq.IDENTITY, 'utf16')
self.assertEqual(identu, identu2)
time.sleep(0.1) # wait for connection/subscription
p.send_unicode(topic,zmq.SNDMORE)
p.send_unicode(topic*2, encoding='latin-1')
self.assertEqual(topic, s.recv_unicode())
self.assertEqual(topic*2, s.recv_unicode(encoding='latin-1'))
示例3: test_hwm
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def test_hwm(self):
zmq3 = zmq.zmq_version_info()[0] >= 3
for stype in (zmq.PUB, zmq.ROUTER, zmq.SUB, zmq.REQ, zmq.DEALER):
s = self.context.socket(stype)
s.hwm = 100
self.assertEqual(s.hwm, 100)
if zmq3:
try:
self.assertEqual(s.sndhwm, 100)
except AttributeError:
pass
try:
self.assertEqual(s.rcvhwm, 100)
except AttributeError:
pass
s.close()
示例4: test_subscribe_method
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def test_subscribe_method(self):
pub, sub = self.create_bound_pair(zmq.PUB, zmq.SUB)
sub.subscribe('prefix')
sub.subscribe = 'c'
p = zmq.Poller()
p.register(sub, zmq.POLLIN)
# wait for subscription handshake
for i in range(100):
pub.send(b'canary')
events = p.poll(250)
if events:
break
self.recv(sub)
pub.send(b'prefixmessage')
msg = self.recv(sub)
self.assertEqual(msg, b'prefixmessage')
sub.unsubscribe('prefix')
pub.send(b'prefixmessage')
events = p.poll(1000)
self.assertEqual(events, [])
# Travis can't handle how much memory PyPy uses on this test
示例5: test_shadow
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def test_shadow(self):
ctx = self.Context()
ctx2 = self.Context.shadow(ctx.underlying)
self.assertEqual(ctx.underlying, ctx2.underlying)
s = ctx.socket(zmq.PUB)
s.close()
del ctx2
self.assertFalse(ctx.closed)
s = ctx.socket(zmq.PUB)
ctx2 = self.Context.shadow(ctx.underlying)
s2 = ctx2.socket(zmq.PUB)
s.close()
s2.close()
ctx.term()
self.assertRaisesErrno(zmq.EFAULT, ctx2.socket, zmq.PUB)
del ctx2
示例6: test_skt_reinit
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def test_skt_reinit():
result = {'foo': None, 'bar': None}
@socket(zmq.PUB)
def f(key, skt):
assert isinstance(skt, zmq.Socket), skt
result[key] = skt
foo_t = threading.Thread(target=f, args=('foo',))
bar_t = threading.Thread(target=f, args=('bar',))
foo_t.start()
bar_t.start()
foo_t.join()
bar_t.join()
assert result['foo'] is not None, result
assert result['bar'] is not None, result
assert result['foo'] is not result['bar'], result
示例7: test_multi_skts
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def test_multi_skts():
@socket(zmq.PUB)
@socket(zmq.SUB)
@socket(zmq.PUSH)
def test(pub, sub, push):
assert isinstance(pub, zmq.Socket), pub
assert isinstance(sub, zmq.Socket), sub
assert isinstance(push, zmq.Socket), push
assert pub.context is zmq.Context.instance()
assert sub.context is zmq.Context.instance()
assert push.context is zmq.Context.instance()
assert pub.type == zmq.PUB
assert sub.type == zmq.SUB
assert push.type == zmq.PUSH
test()
示例8: test_multi_skts_single_ctx
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def test_multi_skts_single_ctx():
@context()
@socket(zmq.PUB)
@socket(zmq.SUB)
@socket(zmq.PUSH)
def test(ctx, pub, sub, push):
assert isinstance(ctx, zmq.Context), ctx
assert isinstance(pub, zmq.Socket), pub
assert isinstance(sub, zmq.Socket), sub
assert isinstance(push, zmq.Socket), push
assert pub.context is ctx
assert sub.context is ctx
assert push.context is ctx
assert pub.type == zmq.PUB
assert sub.type == zmq.SUB
assert push.type == zmq.PUSH
test()
示例9: test_multi_skts_with_name
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def test_multi_skts_with_name():
@socket('foo', zmq.PUSH)
@socket('bar', zmq.SUB)
@socket('baz', zmq.PUB)
def test(foo, bar, baz):
assert isinstance(foo, zmq.Socket), foo
assert isinstance(bar, zmq.Socket), bar
assert isinstance(baz, zmq.Socket), baz
assert foo.context is zmq.Context.instance()
assert bar.context is zmq.Context.instance()
assert baz.context is zmq.Context.instance()
assert foo.type == zmq.PUSH
assert bar.type == zmq.SUB
assert baz.type == zmq.PUB
test()
示例10: multi_skts_method_other_args
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def multi_skts_method_other_args(self):
@socket(zmq.PUB)
@socket(zmq.SUB)
def f(foo, pub, sub, bar=None):
assert isinstance(pub, zmq.Socket), pub
assert isinstance(sub, zmq.Socket), sub
assert foo == 'mock'
assert bar == 'fake'
assert pub.context is zmq.Context.instance()
assert sub.context is zmq.Context.instance()
assert pub.type is zmq.PUB
assert sub.type is zmq.SUB
f('mock', bar='fake')
示例11: build_device
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def build_device(self, mon_sub=b"", in_prefix=b'in', out_prefix=b'out'):
self.device = devices.ThreadMonitoredQueue(zmq.PAIR, zmq.PAIR, zmq.PUB,
in_prefix, out_prefix)
alice = self.context.socket(zmq.PAIR)
bob = self.context.socket(zmq.PAIR)
mon = self.context.socket(zmq.SUB)
aport = alice.bind_to_random_port('tcp://127.0.0.1')
bport = bob.bind_to_random_port('tcp://127.0.0.1')
mport = mon.bind_to_random_port('tcp://127.0.0.1')
mon.setsockopt(zmq.SUBSCRIBE, mon_sub)
self.device.connect_in("tcp://127.0.0.1:%i"%aport)
self.device.connect_out("tcp://127.0.0.1:%i"%bport)
self.device.connect_mon("tcp://127.0.0.1:%i"%mport)
self.device.start()
time.sleep(.2)
try:
# this is currenlty necessary to ensure no dropped monitor messages
# see LIBZMQ-248 for more info
mon.recv_multipart(zmq.NOBLOCK)
except zmq.ZMQError:
pass
self.sockets.extend([alice, bob, mon])
return alice, bob, mon
示例12: __init__
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def __init__(self, repAddress, pubAddress):
"""Constructor"""
# 调用RpcObject的构造器:self.usePickle()
super(RpcServer, self).__init__()
# 保存功能函数的字典,key是函数名,value是函数对象
self.__functions = {}
# zmq端口相关
self.__context = zmq.Context()
self.__socketREP = self.__context.socket(zmq.REP) # 请求回应socket
self.__socketREP.bind(repAddress)
self.__socketPUB = self.__context.socket(zmq.PUB) # 数据广播socket
self.__socketPUB.bind(pubAddress)
# 工作线程相关
self.__active = False # 服务器的工作状态
self.__thread = threading.Thread(target=self.run) # 服务器的工作线程
#----------------------------------------------------------------------
示例13: __init__
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def __init__(self):
super().__init__()
# Init lists
self.ipAddressesList = ["All"]
self.spacecraftNames = ["All"]
self.specialPktId = []
self.specialPktName = []
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Init zeroMQ
self.context = zmq.Context()
self.publisher = self.context.socket(zmq.PUB)
self.publisher.bind("ipc:///tmp/GroundSystem")
# Run thread
示例14: get_kernel
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def get_kernel(kernel_class=SpyderKernel):
"""Get an instance of a kernel with the kernel class given."""
log = logging.getLogger('test')
log.setLevel(logging.DEBUG)
for hdlr in log.handlers:
log.removeHandler(hdlr)
hdlr = logging.StreamHandler(StringIO())
hdlr.setLevel(logging.DEBUG)
log.addHandler(hdlr)
context = zmq.Context.instance()
iopub_socket = context.socket(zmq.PUB)
kernel = kernel_class(session=ss.Session(), iopub_socket=iopub_socket,
log=log)
return kernel
示例15: __init__
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import PUB [as 别名]
def __init__(self, in_addr, out_addr, mon_addr=None, in_type=zmq.SUB, out_type=zmq.DEALER, mon_type=zmq.PUB, heart_id=None):
if mon_addr is None:
self.device = ThreadDevice(zmq.FORWARDER, in_type, out_type)
else:
self.device = ThreadMonitoredQueue(in_type, out_type, mon_type, in_prefix=b"", out_prefix=b"")
# do not allow the device to share global Context.instance,
# which is the default behavior in pyzmq > 2.1.10
self.device.context_factory = zmq.Context
self.device.daemon=True
self.device.connect_in(in_addr)
self.device.connect_out(out_addr)
if mon_addr is not None:
self.device.connect_mon(mon_addr)
if in_type == zmq.SUB:
self.device.setsockopt_in(zmq.SUBSCRIBE, b"")
if heart_id is None:
heart_id = uuid.uuid4().bytes
self.device.setsockopt_out(zmq.IDENTITY, heart_id)
self.id = heart_id