当前位置: 首页>>代码示例>>Python>>正文


Python registry.ActorRegistry类代码示例

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


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

示例1: _actor_loop

    def _actor_loop(self):
        """
        The actor's event loop.

        This is the method that will be executed by the thread or greenlet.
        """
        self.on_start()
        while self._actor_runnable:
            message = self.actor_inbox.get()
            try:
                response = self._handle_receive(message)
                if 'reply_to' in message:
                    message['reply_to'].set(response)
            except Exception:
                if 'reply_to' in message:
                    _logger.debug(
                        'Exception returned from %s to caller:' % self,
                        exc_info=_sys.exc_info())
                    message['reply_to'].set_exception()
                else:
                    self._handle_failure(*_sys.exc_info())
            except BaseException:
                exception_value = _sys.exc_info()[1]
                _logger.debug(
                    '%s in %s. Stopping all actors.' %
                    (repr(exception_value), self))
                self._stop()
                _ActorRegistry.stop_all()
开发者ID:davisein,项目名称:pykka,代码行数:28,代码来源:actor.py

示例2: _handle_failure

 def _handle_failure(self, exception_type, exception_value, traceback):
     """Logs unexpected failures, unregisters and stops the actor."""
     logger.error(
         'Unhandled exception in %s:' % self,
         exc_info=(exception_type, exception_value, traceback))
     ActorRegistry.unregister(self.actor_ref)
     self.actor_stopped.set()
开发者ID:0xD3ADB33F,项目名称:pykka,代码行数:7,代码来源:actor.py

示例3: scan_command

def scan_command(directory, tagfile='STAG.sqlite', verbose=False):
    """Scan a directory tree for definitions and references."""

    init_logging(verbose)

    with StorageManager(Storage(tagfile)) as s:
        s.clear_defs()

        storage = StorageActor.start(s)
        parser_map = [
            (list(p.patterns()),
             ParserActor.start(p.create_parser(), storage))
            for p in parser_plugins()]

        dispatcher = DispatcherActor.start(parser_map)

        def dispatch_file(args):
            "Send results of os.walk to the dispatcher."
            dirpath, _, filenames = args
            for fname in filenames:
                dispatcher.tell({
                    'command': 'dispatch',
                    'filename': os.path.join(dirpath, fname)
        })

        emap(dispatch_file, os.walk(directory))

        # Shut everything down.
        ActorRegistry.stop_all()
开发者ID:abingham,项目名称:stag,代码行数:29,代码来源:app.py

示例4: _handle_failure

 def _handle_failure(self, exception_type, exception_value, traceback):
     """Logs unexpected failures, unregisters and stops the actor."""
     _logger.error('Unhandled exception in %s:' % self,
         exc_info=(exception_type, exception_value, traceback))
     _ActorRegistry.unregister(self.actor_ref)
     self._actor_runnable = False
     self.on_failure(exception_type, exception_value, traceback)
开发者ID:zombiecalypse,项目名称:pykka,代码行数:7,代码来源:actor.py

示例5: _run

    def _run(self):
        """
        The actor's main method.

        :class:`pykka.gevent.GeventActor` expects this method to be named
        :meth:`_run`.

        :class:`ThreadingActor` expects this method to be named :meth:`run`.
        """
        self.on_start()
        while self._actor_runnable:
            try:
                message = self.actor_inbox.get(False)
                _logger.debug('Actor {} got message {}'.format(self, message))
                try:
                    response = self._handle_receive(message)
                    if 'reply_to' in message:
                        message['reply_to'].set(response)
                except Exception as exception:
                    if 'reply_to' in message:
                        _logger.debug('Exception returned from %s to caller:' %
                            self, exc_info=_sys.exc_info())
                        message['reply_to'].set_exception(exception)
                    else:
                        self._handle_failure(*_sys.exc_info())
                except BaseException as exception:
                    exception_value = _sys.exc_info()[1]
                    _logger.debug('%s in %s. Stopping all actors.' %
                        (repr(exception_value), self))
                    self.stop()
                    _ActorRegistry.stop_all()
            except _queue.Empty:
                pass
开发者ID:zombiecalypse,项目名称:pykka,代码行数:33,代码来源:actor.py

示例6: start

    def start(cls, *args, **kwargs):
        """
        Start an actor and register it in the
        :class:`pykka.registry.ActorRegistry`.

        Any arguments passed to :meth:`start` will be passed on to the class
        constructor.

        Returns a :class:`ActorRef` which can be used to access the actor in a
        safe manner.

        Behind the scenes, the following is happening when you call
        :meth:`start`::

            Actor.start()
                Actor.__new__()
                    superclass.__new__()
                    superclass.__init__()
                    URN assignment
                    Inbox creation
                    ActorRef creation
                Actor.__init__()        # Your code can run here
                ActorRegistry.register()
                superclass.start()
        """
        obj = cls(*args, **kwargs)
        _ActorRegistry.register(obj.actor_ref)
        cls._superclass.start(obj)
        _logger.debug('Started %s', obj)
        return obj.actor_ref
开发者ID:zombiecalypse,项目名称:pykka,代码行数:30,代码来源:actor.py

示例7: _stop

 def _stop(self):
     """
     Stops the actor immediately without processing the rest of the inbox.
     """
     _ActorRegistry.unregister(self.actor_ref)
     self._actor_runnable = False
     _logger.debug('Stopped %s', self)
     self.on_stop()
开发者ID:davisein,项目名称:pykka,代码行数:8,代码来源:actor.py

示例8: test_broadcast_sends_message_to_all_actors_of_given_class_name

 def test_broadcast_sends_message_to_all_actors_of_given_class_name(self):
     ActorRegistry.broadcast({'command': 'foo'}, target_class='AnActor')
     for actor_ref in ActorRegistry.get_by_class(self.AnActor):
         received_messages = actor_ref.proxy().received_messages.get()
         self.assert_({'command': 'foo'} in received_messages)
     for actor_ref in ActorRegistry.get_by_class(self.BeeActor):
         received_messages = actor_ref.proxy().received_messages.get()
         self.assert_({'command': 'foo'} not in received_messages)
开发者ID:benjixx,项目名称:pykka,代码行数:8,代码来源:registry_test.py

示例9: setup

    def setup(self):
        gstreamer_refs = ActorRegistry.get_by_class(GStreamer)
        assert len(gstreamer_refs) == 1, \
            'Expected exactly one running gstreamer.'
        self.gstreamer = gstreamer_refs[0].proxy()

        backend_refs = ActorRegistry.get_by_class(Backend)
        assert len(backend_refs) == 1, 'Expected exactly one running backend.'
        self.backend = backend_refs[0].proxy()
开发者ID:WoLpH,项目名称:mopidy,代码行数:9,代码来源:session_manager.py

示例10: setup

    def setup(self):
        audio_refs = ActorRegistry.get_by_class(audio.Audio)
        assert len(audio_refs) == 1, \
            'Expected exactly one running Audio instance.'
        self.audio = audio_refs[0].proxy()

        backend_refs = ActorRegistry.get_by_class(Backend)
        assert len(backend_refs) == 1, 'Expected exactly one running backend.'
        self.backend = backend_refs[0].proxy()
开发者ID:Dvad,项目名称:mopidy,代码行数:9,代码来源:session_manager.py

示例11: stop_all_actors

def stop_all_actors():
    num_actors = len(ActorRegistry.get_all())
    while num_actors:
        logger.debug(u'Seeing %d actor and %d non-actor thread(s): %s',
            num_actors, threading.active_count() - num_actors,
            ', '.join([t.name for t in threading.enumerate()]))
        logger.debug(u'Stopping %d actor(s)...', num_actors)
        ActorRegistry.stop_all()
        num_actors = len(ActorRegistry.get_all())
    logger.debug(u'All actors stopped.')
开发者ID:Amli,项目名称:mopidy,代码行数:10,代码来源:process.py

示例12: stop

 def stop(self):
     logger.info("exiting ...")
     logger.info("waiting for actors to stop ...")
     try:
         ActorRegistry.stop_all(timeout=10)
     except Exception as ex:
         logger.info("warning - actors failed to stop cleanly")
     logger.info("stopping web server ...")
     stop_web()
     logger.info("finished")
开发者ID:kieranelby,项目名称:mormuvid,代码行数:10,代码来源:app.py

示例13: stop

    def stop(self):
        """
        Stop the actor.

        The actor will finish processing any messages already in its queue
        before stopping. It may not be restarted.
        """
        self.actor_runnable = False
        ActorRegistry.unregister(self.actor_ref)
        logger.debug(u'Stopped %s', self)
开发者ID:flaper87,项目名称:pykka,代码行数:10,代码来源:actor.py

示例14: test_actor_may_be_unregistered_multiple_times_without_error

 def test_actor_may_be_unregistered_multiple_times_without_error(self):
     ActorRegistry.unregister(self.ref)
     self.assert_(self.ref not in ActorRegistry.get_all())
     ActorRegistry.unregister(self.ref)
     self.assert_(self.ref not in ActorRegistry.get_all())
     ActorRegistry.register(self.ref)
     self.assert_(self.ref in ActorRegistry.get_all())
开发者ID:benjixx,项目名称:pykka,代码行数:7,代码来源:registry_test.py

示例15: _stop

 def _stop(self):
     """
     Stops the actor immediately without processing the rest of the inbox.
     """
     _ActorRegistry.unregister(self.actor_ref)
     self._actor_runnable = False
     _logger.debug('Stopped %s', self)
     try:
         self.on_stop()
     except Exception:
         self._handle_failure(*_sys.exc_info())
开发者ID:jstasiak,项目名称:pykka,代码行数:11,代码来源:actor.py


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