• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python pulsar.multi_async函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pulsar.multi_async函数的典型用法代码示例。如果您正苦于以下问题:Python multi_async函数的具体用法?Python multi_async怎么用?Python multi_async使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了multi_async函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:JinsongBian,项目名称:pulsar,代码行数:56,代码来源:tests.py


示例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)
开发者ID:Danzeer,项目名称:pulsar,代码行数:55,代码来源:tests.py


示例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)
开发者ID:rennat,项目名称:pulsar,代码行数:51,代码来源:tests.py


示例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)
开发者ID:BazookaShao,项目名称:pulsar,代码行数:7,代码来源:tx.py


示例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))
开发者ID:pombredanne,项目名称:lux,代码行数:7,代码来源:wrappers.py


示例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)
开发者ID:imclab,项目名称:pulsar,代码行数:7,代码来源:content.py


示例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)
开发者ID:rennat,项目名称:pulsar,代码行数:7,代码来源:tests.py


示例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)
开发者ID:axisofentropy,项目名称:pulsar,代码行数:7,代码来源:mapper.py


示例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)
开发者ID:JinsongBian,项目名称:pulsar,代码行数:32,代码来源:case.py


示例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)
开发者ID:JinsongBian,项目名称:pulsar,代码行数:7,代码来源:mapper.py


示例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)
开发者ID:axisofentropy,项目名称:pulsar,代码行数:8,代码来源:eventloop.py


示例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)
开发者ID:elimisteve,项目名称:pulsar,代码行数:8,代码来源:eventloop.py


示例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)
开发者ID:AlecTaylor,项目名称:python-stdnet,代码行数:8,代码来源:fknotrequired.py


示例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)
开发者ID:JinsongBian,项目名称:pulsar,代码行数:8,代码来源:greenio.py


示例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)
开发者ID:BazookaShao,项目名称:pulsar,代码行数:8,代码来源:content.py


示例16: do_stream

 def do_stream(self, request):
     # stream the body
     body = multi_async(self.body.stream(request))
     # the body has asynchronous components
     # delay the header untl later
     if not body.done():
         yield self._html(request, body)
     else:
         head = multi_async(self.head.stream(request))
         #
         # header not ready (this should never occur really)
         if not head.done():
             yield self._html(request, body, head)
         else:
             yield self._template % (self.flatatt(),
                                     self.head.to_string(head.result()),
                                     self.body.to_string(body.result()))
开发者ID:imclab,项目名称:pulsar,代码行数:17,代码来源:content.py


示例17: monitor_start

    def monitor_start(self, monitor):
        '''When the monitor starts load all test classes into the queue'''
        # Create a datastore for this test suite
        if not self.cfg.task_backend:
            server = PulsarDS(bind='127.0.0.1:0', workers=0,
                              key_value_save=[],
                              name='%s_store' % self.name)
            yield server()
            address = 'pulsar://%s:%s' % server.cfg.addresses[0]
        else:
            address = self.cfg.task_backend

        store = create_store(address, pool_size=2, loop=monitor._loop)
        self.get_backend(store)
        loader = self.loader
        tags = self.cfg.labels
        exclude_tags = self.cfg.exclude_labels
        if self.cfg.show_leaks:
            show = show_leaks if self.cfg.show_leaks == 1 else hide_leaks
            self.cfg.set('when_exit', show)
            arbiter = pulsar.arbiter()
            arbiter.cfg.set('when_exit', show)
        try:
            tests = []
            loader.runner.on_start()
            for tag, testcls in loader.testclasses(tags, exclude_tags):
                suite = loader.runner.loadTestsFromTestCase(testcls)
                if suite and suite._tests:
                    tests.append((tag, testcls))
            self._time_start = None
            if tests:
                self.logger.info('loading %s test classes', len(tests))
                monitor.cfg.set('workers', min(self.cfg.workers, len(tests)))
                self._time_start = default_timer()
                queued = []
                self._tests_done = set()
                self._tests_queued = None
                #
                # Bind to the task_done event
                self.backend.bind_event('task_done',
                                        partial(self._test_done, monitor))
                for tag, testcls in tests:
                    r = self.backend.queue_task('test', testcls=testcls,
                                                tag=tag)
                    queued.append(r)
                queued = yield multi_async(queued)
                self.logger.debug('loaded %s test classes', len(tests))
                self._tests_queued = set(queued)
                yield self._test_done(monitor)
            else:   # pragma    nocover
                raise ExitTest('Could not find any tests.')
        except ExitTest as e:   # pragma    nocover
            monitor.stream.writeln(str(e))
            monitor.arbiter.stop()
        except Exception:   # pragma    nocover
            monitor.logger.critical('Error occurred while starting tests',
                                    exc_info=True)
            monitor._loop.call_soon(self._exit, 3)
开发者ID:JinsongBian,项目名称:pulsar,代码行数:58,代码来源:__init__.py


示例18: _html

 def _html(self, request, body, head=None):
     if head is None:
         body = yield body
         head = multi_async(self.head.stream(request))
     head = yield head
     result = self._template % (self.flatatt(),
                                self.head.to_string(head),
                                self.body.to_string(body))
     coroutine_return(result)
开发者ID:imclab,项目名称:pulsar,代码行数:9,代码来源:content.py


示例19: test_ping_test_worker

 def test_ping_test_worker(self):
     arbiter = pulsar.get_actor()
     info = arbiter.info()
     test = info['monitors']['test']
     workers = [w['actor']['actor_id'] for w in test['workers']]
     self.assertTrue(workers)
     result = yield multi_async((arbiter.send(w, 'ping') for w in workers))
     self.assertEqual(len(result), len(workers))
     self.assertEqual(result, len(result)*['pong'])
开发者ID:axisofentropy,项目名称:pulsar,代码行数:9,代码来源:arbiter.py


示例20: test_multi

 def test_multi(self):
     d1 = Future()
     d2 = Future()
     d = multi_async([d1, d2, "bla"])
     self.assertFalse(d.done())
     d2.set_result("first")
     self.assertFalse(d.done())
     d1.set_result("second")
     result = yield from d
     self.assertEqual(result, ["second", "first", "bla"])
开发者ID:dejlek,项目名称:pulsar,代码行数:10,代码来源:multi.py



注:本文中的pulsar.multi_async函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pulsar.send函数代码示例发布时间:2022-05-25
下一篇:
Python pulsar.get_event_loop函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap