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

Python pulsar.arbiter函数代码示例

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

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



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

示例1: __call__

 def __call__(self, a=None):
     if a is None:
         a = yield spawn(name='greeter')
     if names:
         name = names.pop()
         send(a, 'greetme', {'name': name})
         self._loop.call_later(1, self, a)
     else:
         arbiter().stop()
开发者ID:JinsongBian,项目名称:pulsar,代码行数:9,代码来源:greeter.py


示例2: __call__

 async def __call__(self, a=None):
     if a is None:
         a = await pulsar.spawn(name='greeter')
     if names:
         name = names.pop()
         self._loop.logger.info("Hi! I'm %s" % name)
         await pulsar.send(a, 'greetme', {'name': name})
         self._loop.call_later(1, pulsar.ensure_future, self(a))
     else:
         pulsar.arbiter().stop()
开发者ID:juanignaciocatalano,项目名称:pulsar,代码行数:10,代码来源:greeter.py


示例3: main

 def main(self):
     arbiter = pulsar.arbiter()
     arbiter.log.info('%s - starting up the service' % self._svc_name_)
     self.running = True
     while self.running:
         time.sleep(1)
     arbiter.log.info('%s - exiting up the service' % self._svc_name_)
开发者ID:JinsongBian,项目名称:pulsar,代码行数:7,代码来源:winservice.py


示例4: __call__

    def __call__(self, actor=None):
        '''Register this application with the (optional) calling ``actor``.

        If an ``actor`` is available (either via the function argument or via
        the :func:`~pulsar.async.actor.get_actor` function) it must be
        :class:`.Arbiter`, otherwise this call is no-op.

        If no actor is available, it means this application starts
        pulsar engine by creating the :class:`.Arbiter` with its
        :ref:`global settings <setting-section-global-server-settings>`
        copied to the arbiter :class:`.Config` container.

        :return: the ``start`` one time event fired once this application
            has fired it.
        '''
        if actor is None:
            actor = get_actor()
        monitor = None
        if actor and actor.is_arbiter():
            monitor = actor.get_actor(self.name)
        if monitor is None and (not actor or actor.is_arbiter()):
            self.cfg.on_start()
            self.logger = self.cfg.configured_logger()
            if not actor:
                actor = pulsar.arbiter(cfg=self.cfg.clone())
            else:
                self.update_arbiter_params(actor)
            self.cfg.set('exc_id', actor.cfg.exc_id)
            if self.on_config(actor) is not False:
                start = Future(loop=actor._loop)
                actor.bind_event('start', partial(self._add_monitor, start))
                return start
            else:
                return
        raise ImproperlyConfigured('Already started or not in arbiter domain')
开发者ID:huobao36,项目名称:pulsar,代码行数:35,代码来源:__init__.py


示例5: monitor_start

    def monitor_start(self, monitor):
        '''When the monitor starts load all test classes into the queue'''
        cfg = self.cfg
        workers = min(0, cfg.workers)
        cfg.set('workers', workers)
        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._loop.call_soon(Runner, monitor, loader.runner, tests)
            else:   # pragma    nocover
                raise ExitTest('Could not find any tests.')
        except ExitTest as e:   # pragma    nocover
            monitor.stream.writeln(str(e))
            monitor._loop.stop()
        except Exception:   # pragma    nocover
            monitor.logger.critical('Error occurred while starting tests',
                                    exc_info=True)
            monitor._loop.call_soon(self._exit, 3)
开发者ID:Danzeer,项目名称:pulsar,代码行数:34,代码来源:__init__.py


示例6: __init__

 def __init__(self):
     cfg = pulsar.Config()
     cfg.parse_command_line()
     a = pulsar.arbiter(cfg=cfg)
     self.cfg = a.cfg
     self._loop = a._loop
     self._loop.call_later(1, pulsar.ensure_future, self())
     a.start()
开发者ID:juanignaciocatalano,项目名称:pulsar,代码行数:8,代码来源:greeter.py


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


示例8: start

    def start(self):
        """Start the :class:`pulsar.Arbiter` if it wasn't already started.

        Calling this method when the :class:`pulsar.Arbiter` is already
        running has no effect.
        """
        on_start = self()
        arbiter = pulsar.arbiter()
        if arbiter and on_start:
            arbiter.start()
        return self
开发者ID:pombredanne,项目名称:pulsar,代码行数:11,代码来源:__init__.py


示例9: __call__

 def __call__(self, argv, start=True):
     app = self.app
     server = self.pulsar_app(argv, wsgi.WSGIServer)
     if start and not server.logger:   # pragma    nocover
         if not pulsar.get_actor():
             clear_logger()
         app._started = server()
         app.on_start(server)
         arbiter = pulsar.arbiter()
         arbiter.start()
     return app
开发者ID:victor3rc,项目名称:lux,代码行数:11,代码来源:serve.py


示例10: testArbiterObject

 def testArbiterObject(self):
     '''Test the arbiter in its process domain'''
     arbiter = pulsar.get_actor()
     self.assertEqual(arbiter, pulsar.arbiter())
     self.assertTrue(arbiter.is_arbiter())
     self.assertEqual(arbiter.impl.kind, 'arbiter')
     self.assertTrue(arbiter.monitors)
     self.assertEqual(arbiter.exit_code, None)
     info = arbiter.info()
     self.assertTrue('server' in info)
     server = info['server']
     self.assertEqual(server['state'], 'running')
开发者ID:JinsongBian,项目名称:pulsar,代码行数:12,代码来源:arbiter.py


示例11: start

    def start(self):
        '''Invoked the application callable method and start
        the ``arbiter`` if it wasn't already started.

        It returns a :class:`~asyncio.Future` called back once the
        application/applications are running. It returns ``None`` if
        called more than once.
        '''
        on_start = self()
        arbiter = pulsar.arbiter()
        if arbiter and on_start:
            arbiter.start()
        return on_start
开发者ID:jklgithub,项目名称:pulsar,代码行数:13,代码来源:__init__.py


示例12: __call__

    def __call__(self, argv, start=True):
        app = self.app
        server = self.pulsar_app(argv, wsgi.WSGIServer)
        if server.cfg.nominify:
            app.params["MINIFIED_MEDIA"] = False

        if start and not server.logger:  # pragma    nocover
            if not pulsar.get_actor():
                clear_logger()
            app._started = server()
            app.on_start(server)
            arbiter = pulsar.arbiter()
            arbiter.start()
        return app
开发者ID:pvanderlinden,项目名称:lux,代码行数:14,代码来源:serve.py


示例13: start

    def start(self, exit=True):
        """Invoked the application callable method and start
        the ``arbiter`` if it wasn't already started.

        It returns a :class:`~asyncio.Future` called back once the
        application/applications are running. It returns ``None`` if
        called more than once.
        """
        on_start = self()
        arbiter = pulsar.arbiter()
        if arbiter and on_start:
            arbiter.start(exit=exit)
            if arbiter.exit_code is not None:
                return arbiter.exit_code
        return on_start
开发者ID:juanignaciocatalano,项目名称:pulsar,代码行数:15,代码来源:__init__.py


示例14: wait_for_stop

def wait_for_stop(test, aid, terminating=False):
    """Wait for an actor to stop"""
    arbiter = pulsar.arbiter()
    waiter = pulsar.Future(loop=arbiter._loop)

    def remove():
        test.assertEqual(arbiter.remove_callback("periodic_task", check), 1)
        waiter.set_result(None)

    def check(caller, **kw):
        test.assertEqual(caller, arbiter)
        if not terminating:
            test.assertFalse(aid in arbiter.managed_actors)
        elif aid in arbiter.managed_actors:
            return
        arbiter._loop.call_soon(remove)

    arbiter.bind_event("periodic_task", check)
    return waiter
开发者ID:quantmind,项目名称:pulsar,代码行数:19,代码来源:__init__.py


示例15: __call__

 def __call__(self, actor=None):
     if actor is None:
         actor = get_actor()
     monitor = None
     if actor and actor.is_arbiter():
         monitor = actor.get_actor(self.name)
     if monitor is None and (not actor or actor.is_arbiter()):
         self.cfg.on_start()
         self.configure_logging()
         self.fire_event("ready")
         arbiter = pulsar.arbiter(cfg=arbiter_config(self.cfg))
         if self.on_config(arbiter) is not False:
             if arbiter.started():
                 self._add_to_arbiter(arbiter)
             else:  # the arbiter has not yet started.
                 arbiter.bind_event("start", self._add_to_arbiter)
         else:
             return
     return self.event("start")
开发者ID:pombredanne,项目名称:pulsar,代码行数:19,代码来源:__init__.py


示例16: monitor_start

 def monitor_start(self, monitor):
     '''When the monitor starts load all test classes into the queue'''
     super(TestSuite, self).monitor_start(monitor)
     loader = self.local.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:
         self.local.tests = tests = []
         self.runner.on_start()
         for tag, testcls in loader.testclasses(tags, exclude_tags):
             suite = self.runner.loadTestsFromTestCase(testcls)
             if suite and suite._tests:
                 tests.append((tag, testcls))
         self._time_start = None
         if tests:
             self.logger.info('loaded %s test classes', len(tests))
             self.fire_event('tests', tests=tests)
             monitor.cfg.set('workers', min(self.cfg.workers, len(tests)))
             self._time_start = default_timer()
             for tag, testcls in self.local.tests:
                 self.backend.run('test', testcls, tag)
             monitor.event_loop.call_repeatedly(1, self._check_queue)
         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
         self.logger.critical('Error occurred before starting tests',
                              exc_info=True)
         monitor.arbiter.stop()
开发者ID:BazookaShao,项目名称:pulsar,代码行数:36,代码来源:__init__.py


示例17: __call__

 def __call__(self, actor=None):
     if actor is None:
         actor = get_actor()
     monitor = None
     if actor and actor.is_arbiter():
         monitor = actor.monitors.get(self.name)
     if monitor is None and (not actor or actor.is_arbiter()): 
         # Add events
         self.local.events = dict(app_events(self))
         self.cfg.on_start()
         self.configure_logging()
         events.fire('ready', self)
         arbiter = pulsar.arbiter(cfg=self.cfg.new_config())
         if self.on_config() is not False:
             monitor = arbiter.add_monitor(ApplicationMonitor,
                                           self.name,
                                           app=self,
                                           cfg=self.cfg,
                                           ioqueue=self.ioqueue)
             self.cfg = monitor.cfg
             if self.commands_set:
                 monitor.impl.commands_set.update(self.commands_set)
     if self.events:
         return self.events['start']
开发者ID:cyberj,项目名称:pulsar,代码行数:24,代码来源:__init__.py


示例18: __call__

# -*- coding: utf-8 -*-
from pulsar import spawn

import pulsar
import random

class PeriodicTask:
    def __call__(self, actor):
        actor.event_loop.call_repeatedly(2, self.task)

    def task(self):
        print(random.randint(0, 9))

arbiter = pulsar.arbiter()

ap = spawn(start=PeriodicTask())
开发者ID:xmnlab,项目名称:minilab,代码行数:16,代码来源:quick_start.py


示例19: remote_get_value

        request.actor.logger.info('Setting value')
        self.value = value

    def remote_get_value(self, request):
        request.actor.logger.info('Getting value')
        return self.value


def start(arbiter, **kw):
    ensure_future(app(arbiter))


async def app(arbiter):
    # Spawn a new actor
    calc = await Calculator.spawn(name='calc1')
    print(calc.name)
    # set value in the remote calculator
    await calc.set_value(46)
    # get value from the remote calculator
    value = await calc.get_value()
    print(value)

    # Stop the application
    arbiter.stop()


if __name__ == '__main__':
    cfg = Config()
    cfg.parse_command_line()
    arbiter(cfg=cfg, start=start).start()
开发者ID:juanignaciocatalano,项目名称:pulsar,代码行数:30,代码来源:remote.py


示例20: example

from pulsar import arbiter, get_event_loop
from pulsar.apps.greenio import wait, greenlet


def example(loop):
    wait(callback)
    loop.stop()


if __name__ == '__main__':
    a = arbiter()
    loop = a._loop
    loop.call_soon(example, loop)
    a.start()
开发者ID:JinsongBian,项目名称:pulsar,代码行数:14,代码来源:greentest.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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