當前位置: 首頁>>代碼示例>>Python>>正文


Python green.Poller方法代碼示例

本文整理匯總了Python中zmq.green.Poller方法的典型用法代碼示例。如果您正苦於以下問題:Python green.Poller方法的具體用法?Python green.Poller怎麽用?Python green.Poller使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在zmq.green的用法示例。


在下文中一共展示了green.Poller方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from zmq import green [as 別名]
# 或者: from zmq.green import Poller [as 別名]
def __init__(self, sockets, time):
        self.sockets = sockets
        self.poller = zmq.Poller()

        for socket in self.sockets.values():
            self.poller.register(socket["socket"], zmq.POLLIN | zmq.POLLOUT)

        self.time = time 
開發者ID:UFAL-DSG,項目名稱:cloud-asr,代碼行數:10,代碼來源:poller.py

示例2: test_pair

# 需要導入模塊: from zmq import green [as 別名]
# 或者: from zmq.green import Poller [as 別名]
def test_pair(self):
        s1, s2 = self.create_bound_pair(zmq.PAIR, zmq.PAIR)

        # Sleep to allow sockets to connect.
        wait()

        poller = self.Poller()
        poller.register(s1, zmq.POLLIN|zmq.POLLOUT)
        poller.register(s2, zmq.POLLIN|zmq.POLLOUT)
        # Poll result should contain both sockets
        socks = dict(poller.poll())
        # Now make sure that both are send ready.
        self.assertEqual(socks[s1], zmq.POLLOUT)
        self.assertEqual(socks[s2], zmq.POLLOUT)
        # Now do a send on both, wait and test for zmq.POLLOUT|zmq.POLLIN
        s1.send(b'msg1')
        s2.send(b'msg2')
        wait()
        socks = dict(poller.poll())
        self.assertEqual(socks[s1], zmq.POLLOUT|zmq.POLLIN)
        self.assertEqual(socks[s2], zmq.POLLOUT|zmq.POLLIN)
        # Make sure that both are in POLLOUT after recv.
        s1.recv()
        s2.recv()
        socks = dict(poller.poll())
        self.assertEqual(socks[s1], zmq.POLLOUT)
        self.assertEqual(socks[s2], zmq.POLLOUT)

        poller.unregister(s1)
        poller.unregister(s2) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:32,代碼來源:test_poll.py

示例3: test_no_events

# 需要導入模塊: from zmq import green [as 別名]
# 或者: from zmq.green import Poller [as 別名]
def test_no_events(self):
        s1, s2 = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
        poller = self.Poller()
        poller.register(s1, zmq.POLLIN|zmq.POLLOUT)
        poller.register(s2, 0)
        self.assertTrue(s1 in poller)
        self.assertFalse(s2 in poller)
        poller.register(s1, 0)
        self.assertFalse(s1 in poller) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:11,代碼來源:test_poll.py

示例4: test_pubsub

# 需要導入模塊: from zmq import green [as 別名]
# 或者: from zmq.green import Poller [as 別名]
def test_pubsub(self):
        s1, s2 = self.create_bound_pair(zmq.PUB, zmq.SUB)
        s2.setsockopt(zmq.SUBSCRIBE, b'')

        # Sleep to allow sockets to connect.
        wait()

        poller = self.Poller()
        poller.register(s1, zmq.POLLIN|zmq.POLLOUT)
        poller.register(s2, zmq.POLLIN)

        # Now make sure that both are send ready.
        socks = dict(poller.poll())
        self.assertEqual(socks[s1], zmq.POLLOUT)
        self.assertEqual(s2 in socks, 0)
        # Make sure that s1 stays in POLLOUT after a send.
        s1.send(b'msg1')
        socks = dict(poller.poll())
        self.assertEqual(socks[s1], zmq.POLLOUT)

        # Make sure that s2 is POLLIN after waiting.
        wait()
        socks = dict(poller.poll())
        self.assertEqual(socks[s2], zmq.POLLIN)

        # Make sure that s2 goes into 0 after recv.
        s2.recv()
        socks = dict(poller.poll())
        self.assertEqual(s2 in socks, 0)

        poller.unregister(s1)
        poller.unregister(s2) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:34,代碼來源:test_poll.py

示例5: test_raw

# 需要導入模塊: from zmq import green [as 別名]
# 或者: from zmq.green import Poller [as 別名]
def test_raw(self):
        r, w = os.pipe()
        r = os.fdopen(r, 'rb')
        w = os.fdopen(w, 'wb')
        p = self.Poller()
        p.register(r, zmq.POLLIN)
        socks = dict(p.poll(1))
        assert socks == {}
        w.write(b'x')
        w.flush()
        socks = dict(p.poll(1))
        assert socks == {r.fileno(): zmq.POLLIN}
        w.close()
        r.close() 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:16,代碼來源:test_poll.py

示例6: test_wakeup

# 需要導入模塊: from zmq import green [as 別名]
# 或者: from zmq.green import Poller [as 別名]
def test_wakeup(self):
            s1, s2 = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
            poller = self.Poller()
            poller.register(s2, zmq.POLLIN)

            tic = time.time()
            r = gevent.spawn(lambda: poller.poll(10000))
            s = gevent.spawn(lambda: s1.send(b'msg1'))
            r.join()
            toc = time.time()
            self.assertTrue(toc-tic < 1) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:13,代碼來源:test_poll.py

示例7: device

# 需要導入模塊: from zmq import green [as 別名]
# 或者: from zmq.green import Poller [as 別名]
def device(device_type, isocket, osocket):
    """Start a zeromq device (gevent-compatible).
    
    Unlike the true zmq.device, this does not release the GIL.

    Parameters
    ----------
    device_type : (QUEUE, FORWARDER, STREAMER)
        The type of device to start (ignored).
    isocket : Socket
        The Socket instance for the incoming traffic.
    osocket : Socket
        The Socket instance for the outbound traffic.
    """
    p = Poller()
    if osocket == -1:
        osocket = isocket
    p.register(isocket, zmq.POLLIN)
    p.register(osocket, zmq.POLLIN)
    
    while True:
        events = dict(p.poll())
        if isocket in events:
            osocket.send_multipart(isocket.recv_multipart())
        if osocket in events:
            isocket.send_multipart(osocket.recv_multipart()) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:28,代碼來源:device.py

示例8: __init__

# 需要導入模塊: from zmq import green [as 別名]
# 或者: from zmq.green import Poller [as 別名]
def __init__(self):
        self._poller = Poller() 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:4,代碼來源:ioloop.py

示例9: _setup_proxy

# 需要導入模塊: from zmq import green [as 別名]
# 或者: from zmq.green import Poller [as 別名]
def _setup_proxy(self):
        self.frontend = self.context.socket(zmq.XSUB)
        self.frontend.bind(self.XSUB_URL)

        self.backend = self.context.socket(zmq.XPUB)
        self.backend.bind(self.XPUB_URL)

        self.poller = zmq.Poller()
        self.poller.register(self.frontend, zmq.POLLIN)
        self.poller.register(self.backend, zmq.POLLIN) 
開發者ID:NASA-AMMOS,項目名稱:AIT-Core,代碼行數:12,代碼來源:broker.py

示例10: test_reqrep

# 需要導入模塊: from zmq import green [as 別名]
# 或者: from zmq.green import Poller [as 別名]
def test_reqrep(self):
        s1, s2 = self.create_bound_pair(zmq.REP, zmq.REQ)

        # Sleep to allow sockets to connect.
        wait()

        poller = self.Poller()
        poller.register(s1, zmq.POLLIN|zmq.POLLOUT)
        poller.register(s2, zmq.POLLIN|zmq.POLLOUT)

        # Make sure that s1 is in state 0 and s2 is in POLLOUT
        socks = dict(poller.poll())
        self.assertEqual(s1 in socks, 0)
        self.assertEqual(socks[s2], zmq.POLLOUT)

        # Make sure that s2 goes immediately into state 0 after send.
        s2.send(b'msg1')
        socks = dict(poller.poll())
        self.assertEqual(s2 in socks, 0)

        # Make sure that s1 goes into POLLIN state after a time.sleep().
        time.sleep(0.5)
        socks = dict(poller.poll())
        self.assertEqual(socks[s1], zmq.POLLIN)

        # Make sure that s1 goes into POLLOUT after recv.
        s1.recv()
        socks = dict(poller.poll())
        self.assertEqual(socks[s1], zmq.POLLOUT)

        # Make sure s1 goes into state 0 after send.
        s1.send(b'msg2')
        socks = dict(poller.poll())
        self.assertEqual(s1 in socks, 0)

        # Wait and then see that s2 is in POLLIN.
        time.sleep(0.5)
        socks = dict(poller.poll())
        self.assertEqual(socks[s2], zmq.POLLIN)

        # Make sure that s2 is in POLLOUT after recv.
        s2.recv()
        socks = dict(poller.poll())
        self.assertEqual(socks[s2], zmq.POLLOUT)

        poller.unregister(s1)
        poller.unregister(s2) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:49,代碼來源:test_poll.py


注:本文中的zmq.green.Poller方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。