本文整理汇总了Python中pulsar.multi_async函数的典型用法代码示例。如果您正苦于以下问题:Python multi_async函数的具体用法?Python multi_async怎么用?Python multi_async使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了multi_async函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_connection_pool
def test_connection_pool(self):
'''Test the connection pool. A very important test!'''
client = Echo(self.server_cfg.addresses[0], pool_size=2)
self.assertEqual(client.pool.pool_size, 2)
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 0)
self.assertEqual(client.sessions, 0)
self.assertEqual(client._requests_processed, 0)
#
response = yield client(b'test connection')
self.assertEqual(response, b'test connection')
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 1)
self.assertEqual(client.sessions, 1)
self.assertEqual(client._requests_processed, 1)
#
response = yield client(b'test connection 2')
self.assertEqual(response, b'test connection 2')
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 1)
self.assertEqual(client.sessions, 1)
self.assertEqual(client._requests_processed, 2)
#
result = yield multi_async((client(b'ciao'),
client(b'pippo'),
client(b'foo')))
self.assertEqual(len(result), 3)
self.assertTrue(b'ciao' in result)
self.assertTrue(b'pippo' in result)
self.assertTrue(b'foo' in result)
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 2)
self.assertEqual(client.sessions, 2)
self.assertEqual(client._requests_processed, 5)
#
# drop a connection
conn1 = client.pool._queue.get_nowait()
conn1.close()
conn2 = client.pool._queue.get_nowait()
client.pool._queue.put_nowait(conn1)
client.pool._queue.put_nowait(conn2)
#
result = yield multi_async((client(b'ciao'),
client(b'pippo'),
client(b'foo')))
self.assertEqual(len(result), 3)
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 2)
self.assertEqual(client.sessions, 3)
self.assertEqual(client._requests_processed, 8)
#
client.pool.close()
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 0)
self.assertEqual(client.sessions, 3)
self.assertEqual(client._requests_processed, 8)
示例2: test_connection_pool
def test_connection_pool(self):
'''Test the connection pool. A very important test!'''
client = Echo(self.server_cfg.addresses[0], pool_size=2)
self.assertEqual(client._loop, get_event_loop())
#
self.assertEqual(client.pool.pool_size, 2)
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 0)
self.assertEqual(client.sessions, 0)
self.assertEqual(client._requests_processed, 0)
#
response = yield from client(b'test connection')
self.assertEqual(response, b'test connection')
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 1)
self.assertEqual(client.sessions, 1)
self.assertEqual(client._requests_processed, 1)
#
response = yield from client(b'test connection 2')
self.assertEqual(response, b'test connection 2')
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 1)
self.assertEqual(client.sessions, 1)
self.assertEqual(client._requests_processed, 2)
#
result = yield from multi_async((client(b'ciao'),
client(b'pippo'),
client(b'foo')))
self.assertEqual(len(result), 3)
self.assertTrue(b'ciao' in result)
self.assertTrue(b'pippo' in result)
self.assertTrue(b'foo' in result)
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 2)
self.assertEqual(client.sessions, 2)
self.assertEqual(client._requests_processed, 5)
#
# drop a connection
yield from run_in_loop(client._loop, self._drop_conection, client)
#
result = yield from multi_async((client(b'ciao'),
client(b'pippo'),
client(b'foo')))
self.assertEqual(len(result), 3)
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 2)
self.assertEqual(client.sessions, 3)
self.assertEqual(client._requests_processed, 8)
#
yield from run_in_loop(client._loop, client.pool.close)
#
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 0)
self.assertEqual(client.sessions, 3)
self.assertEqual(client._requests_processed, 8)
示例3: test_connection_pool
def test_connection_pool(self):
"""Test the connection pool. A very important test!"""
client = Echo(self.server_cfg.addresses[0], pool_size=2)
self.assertNotEqual(client._loop, get_event_loop())
#
self.assertEqual(client.pool.pool_size, 2)
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 0)
self.assertEqual(client.sessions, 0)
self.assertEqual(client._requests_processed, 0)
#
response = yield client(b"test connection")
self.assertEqual(response, b"test connection")
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 1)
self.assertEqual(client.sessions, 1)
self.assertEqual(client._requests_processed, 1)
#
response = yield client(b"test connection 2")
self.assertEqual(response, b"test connection 2")
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 1)
self.assertEqual(client.sessions, 1)
self.assertEqual(client._requests_processed, 2)
#
result = yield multi_async((client(b"ciao"), client(b"pippo"), client(b"foo")))
self.assertEqual(len(result), 3)
self.assertTrue(b"ciao" in result)
self.assertTrue(b"pippo" in result)
self.assertTrue(b"foo" in result)
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 2)
self.assertEqual(client.sessions, 2)
self.assertEqual(client._requests_processed, 5)
#
# drop a connection
yield run_in_loop(client._loop, self._drop_conection, client)
#
result = yield multi_async((client(b"ciao"), client(b"pippo"), client(b"foo")))
self.assertEqual(len(result), 3)
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 2)
self.assertEqual(client.sessions, 3)
self.assertEqual(client._requests_processed, 8)
#
yield run_in_loop(client._loop, client.pool.close)
#
self.assertEqual(client.pool.in_use, 0)
self.assertEqual(client.pool.available, 0)
self.assertEqual(client.sessions, 3)
self.assertEqual(client._requests_processed, 8)
示例4: test_multi_requests
def test_multi_requests(self):
client = yield get_client(self.server.address)
requests = (client.send_message('Msg%s' % n) for n in range(20))
results = yield multi_async(requests)
self.assertEqual(len(results), 20)
for n, result in enumerate(results):
self.assertEqual(result, 'Msg%s' % n)
示例5: to_json
def to_json(self):
self.body._tag = None
body = yield multi_async(self.body.stream(request))
self.head._tag = None
data = {'body': body}
data.extend(self.head.to_json())
coroutine_return(json.dumps(data))
示例6: stream_mapping
def stream_mapping(value, request=None):
result = {}
for key, value in iteritems(value):
if isinstance(value, AsyncString):
value = value.render(request)
result[key] = value
return multi_async(result)
示例7: test_multi
def test_multi(self):
# need From because this is called by test_client method too
result = yield From(multi_async((self.client(b"ciao"), self.client(b"pippo"), self.client(b"foo"))))
self.assertEqual(len(result), 3)
self.assertTrue(b"ciao" in result)
self.assertTrue(b"pippo" in result)
self.assertTrue(b"foo" in result)
示例8: create_tables
def create_tables(self, remove_existing=False):
'''Loop though :attr:`registered_models` and issue the
:meth:`.Manager.create_table` method.'''
executed = []
for manager in self._registered_models.values():
executed.append(manager.create_table(remove_existing))
return multi_async(executed, loop=self._loop)
示例9: run
def run(self, consumer, runner, testcls, all_tests):
'''Run all test functions from the :attr:`testcls`.
It uses the following algorithm:
* Run the class method ``setUpClass`` of :attr:`testcls` if defined,
unless the test class should be skipped
* Call :meth:`run_test` for each test functions in :attr:`testcls`
* Run the class method ``tearDownClass`` of :attr:`testcls` if defined,
unless the test class should be skipped.
'''
cfg = testcls.cfg
loop = consumer._loop
runner.startTestClass(testcls)
error = None
sequential = getattr(testcls, '_sequential_execution', cfg.sequential)
skip_tests = getattr(testcls, '__unittest_skip__', False)
if not skip_tests:
error = yield self._run(runner, testcls, 'setUpClass',
add_err=False)
# run the tests
if sequential:
# Loop over all test cases in class
for test in all_tests:
yield self.run_test(test, runner, error)
else:
all = (self.run_test(test, runner, error) for test in all_tests)
yield multi_async(all, loop=loop)
if not skip_tests:
yield self._run(runner, testcls, 'tearDownClass', add_err=False)
runner.stopTestClass(testcls)
coroutine_return(runner.result)
示例10: drop_tables
def drop_tables(self):
'''Loop though :attr:`registered_models` and issue the
:meth:`.Manager.drop_table` method.'''
executed = []
for manager in self._registered_models.values():
executed.append(manager.drop_table())
return multi_async(executed, loop=self._loop)
示例11: test_call_at
def test_call_at(self):
loop = get_event_loop()
d1 = Future()
d2 = Future()
c1 = loop.call_at(loop.time()+1, lambda: d1.set_result(loop.time()))
c2 = loop.call_later(1, lambda: d2.set_result(loop.time()))
t1, t2 = yield pulsar.multi_async((d1, d2))
self.assertTrue(t1 <= t2)
示例12: test_call_at
def test_call_at(self):
ioloop = get_event_loop()
d1 = pulsar.Deferred()
d2 = pulsar.Deferred()
c1 = ioloop.call_at(ioloop.timer()+1, lambda: d1.callback(ioloop.timer()))
c2 = ioloop.call_later(1, lambda: d2.callback(ioloop.timer()))
t1, t2 = yield pulsar.multi_async((d1, d2))
self.assertTrue(t1 <= t2)
示例13: test_nodata
def test_nodata(self):
yield self.create_feeds('bla', 'foo')
session = self.session()
feeds = yield session.query(Feed1).filter(name=('bla', 'foo')).all()
for feed in feeds:
live, prev = yield multi_async((feed.live, feed.prev))
self.assertFalse(live)
self.assertFalse(prev)
示例14: test_multi
def test_multi(self):
result = yield multi_async((self.client(b'ciao'),
self.client(b'pippo'),
self.client(b'foo')))
self.assertEqual(len(result), 3)
self.assertTrue(b'ciao' in result)
self.assertTrue(b'pippo' in result)
self.assertTrue(b'foo' in result)
示例15: content
def content(self, request=None):
'''Return a :class:`pulsar.Deferred` called once the string is ready.
This method can be called once only since it invokes the :meth:`stream`
method.
'''
stream = self.stream(request)
return multi_async(stream).add_callback(self.to_string)