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


Python trollius.Future方法代碼示例

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


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

示例1: test_wrong_protocol_exception

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def test_wrong_protocol_exception(self):
        graph = GraphDatabase(url="wss://localhost:8182/", loop=self.loop,
                              future_class=Future)
        @trollius.coroutine
        def go():
            with self.assertRaises(RuntimeError):
                connection = yield From(graph.connect())

        self.loop.run_until_complete(go())


    # def test_bad_host_exception(self):
    #     graph = GraphDatabase(url="ws://locaost:8182/", loop=self.loop,
    #                           future_class=Future)
    #
    #     @trollius.coroutine
    #     def go():
    #         with self.assertRaises(RuntimeError):
    #             connection = yield From(graph.connect())
    #
    #     self.loop.run_until_complete(go()) 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:23,代碼來源:test_trollius.py

示例2: test_maxsize

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def test_maxsize(self):
        pool = Pool(url="ws://localhost:8182/",
                    maxsize=2,
                    username="stephen",
                    password="password",
                    loop=self.loop,
                    future_class=Future)

        @trollius.coroutine
        def go():
            c1 = yield From(pool.acquire())
            c2 = yield From(pool.acquire())
            c3 = pool.acquire()
            self.assertIsInstance(c3, Future)
            with self.assertRaises(trollius.TimeoutError):
                yield From(trollius.wait_for(c3, 0.1))
            c1.conn.close()
            c2.conn.close()

        self.loop.run_until_complete(go()) 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:22,代碼來源:test_trollius.py

示例3: test_release

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def test_release(self):
        pool = Pool(url="ws://localhost:8182/",
                    maxsize=2,
                    username="stephen",
                    password="password",
                    loop=self.loop,
                    future_class=Future)

        @trollius.coroutine
        def go():
            self.assertEqual(len(pool.pool), 0)
            c1 = yield From(pool.acquire())
            self.assertEqual(len(pool._acquired), 1)
            yield From(pool.release(c1))
            self.assertEqual(len(pool.pool), 1)
            self.assertEqual(len(pool._acquired), 0)

        self.loop.run_until_complete(go()) 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:20,代碼來源:test_trollius.py

示例4: test_release_closed

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def test_release_closed(self):
        pool = Pool(url="ws://localhost:8182/",
                    maxsize=2,
                    username="stephen",
                    password="password",
                    future_class=Future)
        self.assertEqual(len(pool.pool), 0)

        @trollius.coroutine
        def go():
            c1 = yield From(pool.acquire())
            self.assertEqual(len(pool._acquired), 1)
            c1.close()
            yield From(pool.release(c1))
            self.assertEqual(len(pool.pool), 0)
            self.assertEqual(len(pool._acquired), 0)
        self.loop.run_until_complete(go()) 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:19,代碼來源:test_trollius.py

示例5: test_self_release

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def test_self_release(self):
        pool = Pool(url="ws://localhost:8182/",
                    maxsize=2,
                    username="stephen",
                    password="password",
                    force_release=True,
                    future_class=Future,
                    loop=self.loop)

        @trollius.coroutine
        def go():
            self.assertEqual(len(pool.pool), 0)
            c1 = yield From(pool.acquire())
            self.assertEqual(len(pool._acquired), 1)
            stream = c1.send("1 + 1")
            resp = yield From(stream.read())
            self.assertEqual(len(pool.pool), 1)
            self.assertEqual(len(pool._acquired), 0)

        self.loop.run_until_complete(go()) 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:22,代碼來源:test_trollius.py

示例6: test_pool_too_big

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def test_pool_too_big(self):

        @trollius.coroutine
        def go():
            pool1 = Pool(url="ws://localhost:8182/",
                         maxsize=2,
                         username="stephen",
                         password="password",
                         future_class=Future)
            pool2 = Pool(url="ws://localhost:8182/",
                         username="stephen",
                         password="password",
                         future_class=Future)
            conn1 = yield From(pool1.acquire())
            conn2 = yield From(pool2.acquire())
            conn3 = yield From(pool2.acquire())
            conn4 = yield From(pool2.acquire())
            pool1.pool.append(conn2)
            pool1.pool.append(conn3)
            pool1.pool.append(conn4)
            yield From(pool1.release(conn1))
            self.assertTrue(conn1.closed)

        self.loop.run_until_complete(go()) 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:26,代碼來源:test_trollius.py

示例7: test_close

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def test_close(self):
        pool = Pool(url="ws://localhost:8182/",
                    maxsize=2,
                    username="stephen",
                    password="password",
                    future_class=Future)

        @trollius.coroutine
        def go():
            c1 = yield From(pool.acquire())
            c2 = yield From(pool.acquire())
            yield From(pool.release(c2))
            pool.close()
            self.assertTrue(c2.conn.closed)
            self.assertFalse(c1.conn.closed)
            c1.close()

        self.loop.run_until_complete(go()) 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:20,代碼來源:test_trollius.py

示例8: test_cancelled

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def test_cancelled(self):
        pool = Pool(url="ws://localhost:8182/",
                    maxsize=2,
                    username="stephen",
                    password="password",
                    future_class=Future)

        @trollius.coroutine
        def go():
            c1 = yield From(pool.acquire())
            c2 = yield From(pool.acquire())
            c3 = pool.acquire()
            pool.close()
            self.assertTrue(c3.cancelled())
            c1.close()
            c2.close()

        self.loop.run_until_complete(go()) 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:20,代碼來源:test_trollius.py

示例9: test_submit

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def test_submit(self):

        @trollius.coroutine
        def go():
            stream = yield From(submit(
                "ws://localhost:8182/", "x + x", bindings={"x": 1},
                password="password", username="stephen", loop=self.loop,
                future_class=Future))
            while True:
                msg = yield From(stream.read())
                if msg is None:
                    break
                self.assertEqual(msg.status_code, 200)
                self.assertEqual(msg.data[0], 2)

        self.loop.run_until_complete(go()) 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:18,代碼來源:test_trollius.py

示例10: to_tornado_future

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def to_tornado_future(asyncio_future):
    """Convert an `asyncio.Future` to a `tornado.concurrent.Future`.

    .. versionadded:: 4.1
    """
    tf = tornado.concurrent.Future()
    tornado.concurrent.chain_future(asyncio_future, tf)
    return tf 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:10,代碼來源:asyncio.py

示例11: to_asyncio_future

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def to_asyncio_future(tornado_future):
    """Convert a Tornado yieldable object to an `asyncio.Future`.

    .. versionadded:: 4.1

    .. versionchanged:: 4.3
       Now accepts any yieldable object, not just
       `tornado.concurrent.Future`.
    """
    tornado_future = convert_yielded(tornado_future)
    af = asyncio.Future()
    tornado.concurrent.chain_future(tornado_future, af)
    return af 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:15,代碼來源:asyncio.py

示例12: setUp

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def setUp(self):
        self.loop = trollius.get_event_loop()
        self.graph = GraphDatabase("ws://localhost:8182/",
                                   username="stephen",
                                   password="password",
                                   loop=self.loop,
                                   future_class=Future) 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:9,代碼來源:test_trollius.py

示例13: test_bad_port_exception

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def test_bad_port_exception(self):
        graph = GraphDatabase(url="ws://localhost:81/", loop=self.loop,
                              future_class=Future)

        @trollius.coroutine
        def go():
            with self.assertRaises(RuntimeError):
                connection = yield From(graph.connect())

        self.loop.run_until_complete(go()) 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:12,代碼來源:test_trollius.py

示例14: test_null_read_on_closed

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def test_null_read_on_closed(self):

        @trollius.coroutine
        def go():
            connection = yield From(self.graph.connect())
            # build connection
            connection.close()
            stream = Stream(connection, None, "processor", None, None, "stephen",
                            "password", False, False, Future)
            with self.assertRaises(RuntimeError):
                msg = yield From(stream.read())

        self.loop.run_until_complete(go())

    # def test_creditials_error(self):
    #
    #     @trollius.coroutine
    #     def go():
    #         graph = GraphDatabase("ws://localhost:8182/",
    #                               username="stephen",
    #                               password="passwor",
    #                               loop=self.loop,
    #                               future_class=Future)
    #         connection = yield From(graph.connect())
    #         resp = connection.send("1 + 1")
    #         with self.assertRaises(RuntimeError):
    #             msg = yield From(resp.read())
    #         connection.conn.close()
    #
    #     self.loop.run_until_complete(go()) 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:32,代碼來源:test_trollius.py

示例15: test_acquire

# 需要導入模塊: import trollius [as 別名]
# 或者: from trollius import Future [as 別名]
def test_acquire(self):
        pool = Pool(url="ws://localhost:8182/",
                    maxsize=2,
                    username="stephen",
                    password="password",
                    loop=self.loop,
                    future_class=Future)

        @trollius.coroutine
        def go():
            connection = yield From(pool.acquire())
            conn = connection.conn
            self.assertFalse(conn.closed)
            self.assertIsInstance(conn, Response)
            self.assertEqual(pool.size, 1)
            self.assertTrue(connection in pool._acquired)
            connection2 = yield From(pool.acquire())
            conn2 = connection.conn
            self.assertFalse(conn2.closed)
            self.assertIsInstance(conn2, Response)
            self.assertEqual(pool.size, 2)
            self.assertTrue(connection2 in pool._acquired)
            conn.close()
            conn2.close()

        self.loop.run_until_complete(go()) 
開發者ID:davebshow,項目名稱:gremlinclient,代碼行數:28,代碼來源:test_trollius.py


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