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

Python pulsar.coroutine_return函数代码示例

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

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



在下文中一共展示了coroutine_return函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: request

    def request(self, method, *bits, **kwargs):
        '''Execute the HTTP request'''
        if self._password:
            try:
                lock = self._lock
                if not lock:
                    self._lock = lock = Lock(loop=self._loop)
                    yield lock.acquire()
                    url = '%s/_session' % self._address
                    response = yield self._http.post(
                        url, data={'name': self._user,
                                   'password': self._password},
                        encode_multipart=False)
                    self.fire_event('request', response)
                    if response.status_code != 200:
                        response.raise_for_status()
                        self._lock = None
                else:
                    yield lock.acquire()
            finally:
                lock.release()
        url = '%s/%s' % (self._address, '/'.join(bits))

        response = yield self._http.request(method, url, data=kwargs,
                                            headers=self.headers)
        self.fire_event('request', response)
        if response.request.method == 'HEAD':
            coroutine_return(response)
        else:
            data = response.decode_content()
            if 'error' in data:
                raise couch_db_error(**data)
            else:
                coroutine_return(data)
开发者ID:huobao36,项目名称:pulsar,代码行数:34,代码来源:store.py


示例2: get_model

 def get_model(self, manager, pkvalue):
     try:
         data = yield self.request('get', self._database, pkvalue)
     except CouchDbError:
         raise odm.ModelNotFound(pkvalue)
     else:
         coroutine_return(self.build_model(manager, data))
开发者ID:huobao36,项目名称:pulsar,代码行数:7,代码来源:store.py


示例3: 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


示例4: execute_transaction

 def execute_transaction(self, transaction):
     '''Execute a ``transaction``
     '''
     updates = []
     models = []
     for command in transaction.commands:
         action = command.action
         if not action:
             raise NotImplementedError
         else:
             model = command.args
             updates.append(dict(self.model_data(model, action)))
             models.append(model)
     #
     if updates:
         executed = yield self.update_documents(self._database, updates)
         errors = []
         for doc, model in zip(executed, models):
             if doc.get('ok'):
                 model['id'] = doc['id']
                 model['_rev'] = doc['rev']
                 model._modified.clear()
             elif doc.get('error'):
                 errors.append(CouchDbError(doc['error'], doc['reason']))
         if errors:
             raise errors[0]
     coroutine_return(models)
开发者ID:JinsongBian,项目名称:pulsar,代码行数:27,代码来源:store.py


示例5: _subscribe

 def _subscribe(self, *args):
     if not self._connection:
         protocol_factory = partial(PubsubProtocol, self,
                                    producer=self.store)
         self._connection = yield self.store.connect(protocol_factory)
         self._connection.execute(*args)
     coroutine_return()
开发者ID:JinsongBian,项目名称:pulsar,代码行数:7,代码来源:pubsub.py


示例6: get_task

 def get_task(self, task_id, timeout):
     if not task_id:
         try:
             task_id = yield self.queue.get(timeout)
         except Empty:
             coroutine_return()
     yield self._tasks.get(task_id)
开发者ID:BazookaShao,项目名称:pulsar,代码行数:7,代码来源:local.py


示例7: execute_pipeline

 def execute_pipeline(self, commands, raise_on_error=True):
     conn = yield self._pool.connect()
     with conn:
         result = yield conn.execute_pipeline(commands, raise_on_error)
         if isinstance(result, ResponseError):
             raise result.exception
         coroutine_return(result)
开发者ID:huobao36,项目名称:pulsar,代码行数:7,代码来源:store.py


示例8: may_pool_task

    def may_pool_task(self, worker):
        '''Called in the ``worker`` event loop.

        It pools a new task if possible, and add it to the queue of
        tasks consumed by the ``worker`` CPU-bound thread.'''
        next_time = 0
        if worker.is_running():
            thread_pool = worker.thread_pool
            if not thread_pool:
                worker.logger.warning('No thread pool, cannot poll tasks.')
            elif self.num_concurrent_tasks < self.backlog:
                if self.max_tasks and self.processed >= self.max_tasks:
                    if not self.num_concurrent_tasks:
                        worker.logger.warning(
                            'Processed %s tasks. Restarting.')
                        worker.stop()
                        coroutine_return()
                else:
                    task = yield self.get_task()
                    if task:    # Got a new task
                        self.processed += 1
                        self.concurrent_tasks.add(task.id)
                        thread_pool.apply(self._execute_task, worker, task)
            else:
                worker.logger.info('%s concurrent requests. Cannot poll.',
                                   self.num_concurrent_tasks)
                next_time = 1
        worker.event_loop.call_later(next_time, self.may_pool_task, worker)
开发者ID:elimisteve,项目名称:pulsar,代码行数:28,代码来源:__init__.py


示例9: _query_view

    def _query_view(self, callback=None, reduce=True, query_type=None, **kw):
        view = self._store.query_model_view
        keys = None
        if self.aggregated:
            view_name = None
            for field, lookups in self.aggregated.items():
                keys = []
                for lookup in lookups:
                    if lookup.type == 'value':
                        keys.append(lookup.value)
                    else:
                        raise NotImplementedError
                if view_name:
                    raise NotImplementedError
                else:
                    view_name = field
        else:
            view_name = 'id'

        if query_type:
            view_name = '%s_%s' % (view_name, query_type)
        kw['keys'] = keys
        try:
            result = yield view(self._meta, view_name, reduce=reduce, **kw)
        except CouchDbNoViewError:
            raise odm.QueryError('Couchdb view for %s not available for %s' %
                                 (view_name, self._meta))
        if callback:
            query = yield callback(result)
        elif reduce:
            query = sum((q['value'] for q in result['rows']))
        else:
            query = self.models((q['doc'] for q in result['rows']))
        coroutine_return(query)
开发者ID:JinsongBian,项目名称:pulsar,代码行数:34,代码来源:query.py


示例10: get_page

 def get_page(self, request, site_id=None, url=None, id=None, **kw):
     '''Retrieve a page instance if not already available.'''
     if 'pages' not in request.cache:
         site_id = request.app.config['SITE_ID']
         page = None
         page_list = yield request.models.page.filter(
             site=site_id).load_related('site').all()
         pages = dict(((p.url, p) for p in page_list))
         pages_id = dict(((str(p.id), p) for p in page_list))
         if id:
             assert url == None, 'url and id should provided together!'
             page = pages_id.get(id)
         elif isinstance(url, (list, tuple)):
             for u in url:
                 page = pages.get(u)
                 if page is not None:
                     break
         else:
             page = pages.get(url)
         if page is None:
             site = yield request.models.site.filter(id=site_id).all()
             if site:
                 site = site[0]
             else:
                 site = yield request.models.site.new(id=site_id)
         else:
             site = page.site
         request.cache.site = site
         request.cache.pages = pages
         request.cache.pages_id = pages
         request.cache.page = page
     coroutine_return(request.cache.page)
开发者ID:pombredanne,项目名称:lux,代码行数:32,代码来源:views.py


示例11: execute

 def execute(self, *args, **options):
     connection = yield self._pool.connect()
     with connection:
         result = yield connection.execute(*args, **options)
         if isinstance(result, ResponseError):
             raise result.exception
         coroutine_return(result)
开发者ID:huobao36,项目名称:pulsar,代码行数:7,代码来源:store.py


示例12: queue_task

 def queue_task(self, request, jobname, meta_data=None, **kw):
     if not jobname:
         raise rpc.InvalidParams('"jobname" is not specified!')
     meta_data = meta_data or {}
     meta_data.update(self.task_request_parameters(request))
     task_backend = yield self.task_backend()
     result = yield task_backend.queue_task(jobname, meta_data, **kw)
     coroutine_return(result)
开发者ID:azziel149,项目名称:pulsar,代码行数:8,代码来源:rpc.py


示例13: _get_app

def _get_app(arbiter, name, safe=True):
    monitor = arbiter.get_actor(name)
    if monitor:
        cfg = yield monitor.start_event
        if safe:
            coroutine_return(cfg)
        else:
            coroutine_return(monitor.app)
开发者ID:Ghost-script,项目名称:dyno-chat,代码行数:8,代码来源:__init__.py


示例14: create_superuser

 def create_superuser(self, request, *args, **kwargs):
     for b in self.auth_backends:
         try:
             user = yield b.create_superuser(request, *args, **kwargs)
             if user is not None:
                 coroutine_return(user)
         except Exception:
             continue
开发者ID:pombredanne,项目名称:lux,代码行数:8,代码来源:permissions.py


示例15: _create_connection

 def _create_connection(self, pair=None):
     '''Default method for connecting to remote datastore.
     '''
     protocol_factory = self.store.create_protocol
     host, port = pair or self.store._host
     _, protocol = yield self._loop.create_connection(
         protocol_factory, host, port)
     socket_info = SocketInfo(protocol, self.pool_id)
     coroutine_return(socket_info)
开发者ID:pombredanne,项目名称:lux,代码行数:9,代码来源:store.py


示例16: authenticate_and_login

    def authenticate_and_login(self, request, user, **params):
        ''':meth:`authenticate` and :meth:`login` a ``user``. Raises
an :class:`AuthenticationError` if the ``user`` could not be authenticated.'''
        if user.is_active:
            user = self.authenticate(request, user, **params)
            user = yield self.login(request, user)
            coroutine_return(user)
        else:
            raise AuthenticationError('%s is not active' % user)
开发者ID:pombredanne,项目名称:lux,代码行数:9,代码来源:permissions.py


示例17: coro1

def coro1():
    done = yield 3
    fut = Future()
    fut._loop.call_soon(fut.set_exception, ValueError('test'))
    try:
        yield fut
    except ValueError:
        done += 1
    coroutine_return(done)
开发者ID:axisofentropy,项目名称:pulsar,代码行数:9,代码来源:coro.py


示例18: rpc_server_info

    def rpc_server_info(self, request):
        '''Return a dictionary of information regarding the server and workers.

        It invokes the :meth:`extra_server_info` for adding custom
        information.
        '''
        info = yield pulsar.send('arbiter', 'info')
        info = yield self.extra_server_info(request, info)
        coroutine_return(info)
开发者ID:azziel149,项目名称:pulsar,代码行数:9,代码来源:mixins.py


示例19: get_router_page

 def get_router_page(self, request):
     handler = request.app_handler
     rule = handler.rule
     path = request.path[1:]
     page = yield self.get_page(request, url=(rule, path))
     if isinstance(page, list):
         pages = dict(((p.url, p) for p in page))
         page = pages.get(path, pages.get(rule))
     coroutine_return(page)
开发者ID:pombredanne,项目名称:lux,代码行数:9,代码来源:views.py


示例20: rpc_job_list

    def rpc_job_list(self, request, jobnames=None):
        '''Return the list of Jobs registered with task queue with meta
        information.

        If a list of ``jobnames`` is given, it returns only jobs
        included in the list.
        '''
        task_backend = yield self.task_backend()
        coroutine_return(task_backend.job_list(jobnames=jobnames))
开发者ID:azziel149,项目名称:pulsar,代码行数:9,代码来源:rpc.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python pulsar.get_actor函数代码示例发布时间:2022-05-25
下一篇:
Python pulsar.arbiter函数代码示例发布时间: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