def __call__(self, argv): app = self.app server = self.pulsar_app(argv, AgileManager) if not server.logger: # pragma nocover app._started = server() pulsar.arbiter().start()
async def _work(self, a=None): if a is None: a = await spawn(name='greeter') if names: name = names.pop() await send(a, 'greetme', {'name': name}) self._loop.call_later(1, self, a) else: arbiter().stop()
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()
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()
def __call__(self, a=None): if a is None: a = yield from pulsar.spawn(name='greeter') if names: name = names.pop() self._loop.logger.info("Hi! I'm %s" % name) yield from pulsar.send(a, 'greetme', {'name': name}) self._loop.call_later(1, pulsar. async, self(a)) else: pulsar.arbiter().stop()
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_)
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._loop.stop() except Exception: # pragma nocover monitor.logger.critical('Error occurred while starting tests', exc_info=True) monitor._loop.call_soon(self._exit, 3)
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')
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)
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()
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. async, self()) a.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)
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
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
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
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')
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
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
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
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
def __call__(self, argv, start=True, get_app=False): self.app.callable.command = self.name app = self.app server = self.pulsar_app(argv, self.wsgiApp) 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() if not start: return app if get_app else server
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')
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
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")
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
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 ``arbiter``, otherwise this call is no-op. If no actor is available, it means this application starts pulsar engine by creating the ``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) if not self.cfg.exc_id: self.cfg.set('exc_id', actor.cfg.exc_id) if self.on_config(actor) is not False: start = create_future(actor._loop) actor.bind_event('start', partial(self._add_monitor, start)) return start else: return elif monitor: raise ImproperlyConfigured('%s already started ' % monitor.name) else: raise ImproperlyConfigured('Cannot start application from %s' % actor)
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']
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()
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()
def SvcStop(self): # self.log.info('%s - Received stop signal' % self._svc_name_) pulsar.arbiter().stop() self.running = False self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop)
'''Write Hello there! every second ''' from pulsar import arbiter def hello(actor, **kw): print('Hello there!') actor._loop.call_later(1, hello, actor) if __name__ == '__main__': arbiter(start=hello).start()
def __init__(self): a = arbiter() self._loop = a._loop self._loop.call_later(1, self) a.start()
def start(self): """Use this method to start all applications at once.""" self.apps() arbiter = pulsar.arbiter() if arbiter: arbiter.start()
def start(self): '''Use this method to start all applications at once.''' self.apps() arbiter = pulsar.arbiter() if arbiter: arbiter.start()
# -*- 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())
def start(self): '''Start the application if it wasn't already started.''' arbiter = pulsar.arbiter() if arbiter and self.name in arbiter.monitors: arbiter.start() return self
def test_no_arbiter_in_worker_domain(self): worker = pulsar.get_actor() self.assertFalse(worker.is_arbiter()) self.assertEqual(pulsar.arbiter(), None) self.assertTrue(worker.monitor) self.assertNotEqual(worker.monitor.name, 'arbiter')
def _exit(self, exit_code): pulsar.arbiter().stop(exit_code=exit_code)
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()
def __call__(self, a=None): act1 = yield from spawn(name='actor1') r = send(act1, 'actor1', dict(data=[1, 2, 4])) r.add_done_callback( lambda resolved_promise: print(resolved_promise.result())) arbiter().stop()
def testArbiter(self): worker = pulsar.get_actor() self.assertEqual(pulsar.arbiter(), None) arbiter = worker.arbiter self.assertTrue(arbiter) self.assertEqual(arbiter.name, 'arbiter')
def SvcStop(self): #self.log.info('%s - Received stop signal' % self._svc_name_) pulsar.arbiter().stop() self.running = False self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop)