本文整理汇总了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())
示例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())
示例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())
示例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())
示例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())
示例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())
示例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())
示例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())
示例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())
示例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
示例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
示例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)
示例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())
示例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())
示例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())