當前位置: 首頁>>代碼示例>>Python>>正文


Python pykka.ActorRegistry類代碼示例

本文整理匯總了Python中pykka.ActorRegistry的典型用法代碼示例。如果您正苦於以下問題:Python ActorRegistry類的具體用法?Python ActorRegistry怎麽用?Python ActorRegistry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ActorRegistry類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _handle_failure

 def _handle_failure(self, exception_type, exception_value, traceback):
     """Logs unexpected failures, unregisters and stops the actor."""
     logger.error(
         'Unhandled exception in {}:'.format(self),
         exc_info=(exception_type, exception_value, traceback),
     )
     ActorRegistry.unregister(self.actor_ref)
     self.actor_stopped.set()
開發者ID:jodal,項目名稱:pykka,代碼行數:8,代碼來源:_actor.py

示例2: test_broadcast_sends_message_to_all_actors_of_given_class

 def test_broadcast_sends_message_to_all_actors_of_given_class(self):
     ActorRegistry.broadcast({'command': 'foo'}, target_class=self.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:0xD3ADB33F,項目名稱:pykka,代碼行數:8,代碼來源:registry_test.py

示例3: _actor_loop

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

        This is the method that will be executed by the thread or greenlet.
        """
        try:
            self.on_start()
        except Exception:
            self._handle_failure(*sys.exc_info())

        while not self.actor_stopped.is_set():
            envelope = self.actor_inbox.get()
            try:
                response = self._handle_receive(envelope.message)
                if envelope.reply_to is not None:
                    envelope.reply_to.set(response)
            except Exception:
                if envelope.reply_to is not None:
                    logger.info(
                        'Exception returned from {} to caller:'.format(self),
                        exc_info=sys.exc_info(),
                    )
                    envelope.reply_to.set_exception()
                else:
                    self._handle_failure(*sys.exc_info())
                    try:
                        self.on_failure(*sys.exc_info())
                    except Exception:
                        self._handle_failure(*sys.exc_info())
            except BaseException:
                exception_value = sys.exc_info()[1]
                logger.debug(
                    '{!r} in {}. Stopping all actors.'.format(
                        exception_value, self
                    )
                )
                self._stop()
                ActorRegistry.stop_all()

        while not self.actor_inbox.empty():
            envelope = self.actor_inbox.get()
            if envelope.reply_to is not None:
                if isinstance(envelope.message, messages._ActorStop):
                    envelope.reply_to.set(None)
                else:
                    envelope.reply_to.set_exception(
                        exc_info=(
                            ActorDeadError,
                            ActorDeadError(
                                '{} stopped before handling the message'.format(
                                    self.actor_ref
                                )
                            ),
                            None,
                        )
                    )
開發者ID:jodal,項目名稱:pykka,代碼行數:57,代碼來源:_actor.py

示例4: 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:0xD3ADB33F,項目名稱:pykka,代碼行數:7,代碼來源:registry_test.py

示例5: _stop

 def _stop(self):
     """
     Stops the actor immediately without processing the rest of the inbox.
     """
     ActorRegistry.unregister(self.actor_ref)
     self.actor_stopped.set()
     logger.debug('Stopped {}'.format(self))
     try:
         self.on_stop()
     except Exception:
         self._handle_failure(*sys.exc_info())
開發者ID:jodal,項目名稱:pykka,代碼行數:11,代碼來源:_actor.py

示例6: test_broadcast_sends_message_to_all_actors_if_no_target

def test_broadcast_sends_message_to_all_actors_if_no_target(
    a_actor_refs, b_actor_refs
):
    ActorRegistry.broadcast({'command': 'foo'})

    running_actors = ActorRegistry.get_all()
    assert running_actors

    for actor_ref in running_actors:
        received_messages = actor_ref.proxy().received_messages.get()
        assert {'command': 'foo'} in received_messages
開發者ID:jodal,項目名稱:pykka,代碼行數:11,代碼來源:test_registry.py

示例7: test_fail

    def test_fail(self):   # pylint: disable=R0201
        """ Test closing stream when fail. """
        def buggy_write(_):
            """ A buggy writable """
            raise ValueError()
        c = Collector.start(self.controller,
                            flexmock(write=buggy_write)
                            .should_receive('close').once().mock())

        c.tell(Record(None, 'Fail'))
        ActorRegistry.stop_all()
開發者ID:spacelis,項目名稱:crawler.kka,代碼行數:11,代碼來源:test_actors.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(
    actor_a_class, actor_b_class
):
    ActorRegistry.broadcast({'command': 'foo'}, target_class='ActorA')

    for actor_ref in ActorRegistry.get_by_class(actor_a_class):
        received_messages = actor_ref.proxy().received_messages.get()
        assert {'command': 'foo'} in received_messages

    for actor_ref in ActorRegistry.get_by_class(actor_b_class):
        received_messages = actor_ref.proxy().received_messages.get()
        assert {'command': 'foo'} not in received_messages
開發者ID:jodal,項目名稱:pykka,代碼行數:12,代碼來源:test_registry.py

示例9: test_all_actors_are_stopped_on_base_exception

def test_all_actors_are_stopped_on_base_exception(events, actor_ref):
    assert len(ActorRegistry.get_all()) == 1
    assert not events.on_stop_was_called.is_set()

    actor_ref.tell({'command': 'raise base exception'})

    events.on_stop_was_called.wait(5)
    assert events.on_stop_was_called.is_set()
    assert len(ActorRegistry.get_all()) == 0

    events.on_stop_was_called.wait(5)
    assert events.on_stop_was_called.is_set()
    assert len(ActorRegistry.get_all()) == 0
開發者ID:jodal,項目名稱:pykka,代碼行數:13,代碼來源:test_actor.py

示例10: test_work

    def test_work(self):
        class Worker(object):
            def __init__(self, arg):
                self.arg = arg

            def work_on(self, task):
                print task
                return task

        flexmock(Worker).should_call('work_on').once().with_args(1)
        cr = Crawler.start(self.controller, self.tasksource, self.collector,
                           Worker, self.initargs)
        cr.tell(Task(None, 1))
        cr.stop()
        ActorRegistry.stop_all()
開發者ID:spacelis,項目名稱:crawler.kka,代碼行數:15,代碼來源:test_actors.py

示例11: send_event

 def send_event(self, event_name, data, player=None, client=None):
     if player:
         data['player'].update(player.get_stats_data())
     if client:
         c = data.get('client', {})
         c['device_type'] = client.device_type
         c['conn_type'] = client.conn_type
         c['client_timestamp'] = client.client_timestamp
         c['client_version'] = client.client_version
         c['device_os'] = client.device_os
         c['device_os_version'] = client.device_os_version
         c['openudid'] = client.openudid
         c['odin'] = client.odin
         c['mac_address'] = client.mac_address
         c['ios_ifa'] = client.ios_ifa
         c['android_id'] = client.android_id
         c['imei'] = client.imei
         c['android_ifa'] = client.android_ifa
         data['client'] = c
     msg = {"event_name": event_name,
            "timestamp": time.time(),
            "data": data}
     actor = ActorRegistry.get_by_class(StatsActor)
     actor = actor and actor[0] or StatsActor.start()
     actor.tell(msg)
開發者ID:sunqi0928,項目名稱:delta-server,代碼行數:25,代碼來源:base_actor.py

示例12: test_stop_all_stops_last_started_actor_first_if_blocking

    def test_stop_all_stops_last_started_actor_first_if_blocking(
            self, mock_method):
        stopped_actors = []
        started_actors = [mock.Mock(name=i) for i in range(3)]
        started_actors[0].stop.side_effect = lambda *a, **kw: \
            stopped_actors.append(started_actors[0])
        started_actors[1].stop.side_effect = lambda *a, **kw: \
            stopped_actors.append(started_actors[1])
        started_actors[2].stop.side_effect = lambda *a, **kw: \
            stopped_actors.append(started_actors[2])
        ActorRegistry.get_all.return_value = started_actors

        ActorRegistry.stop_all(block=True)

        self.assertEqual(stopped_actors[0], started_actors[2])
        self.assertEqual(stopped_actors[1], started_actors[1])
        self.assertEqual(stopped_actors[2], started_actors[0])
開發者ID:0xD3ADB33F,項目名稱:pykka,代碼行數:17,代碼來源:registry_test.py

示例13: __init__

 def __init__(self):
     super(SleepyElder, self).__init__()
     self._lair = ActorRegistry.get_by_class_name('SpiderLair')[0]
     self._lair_command = {
         'command': 'kick_all',
         'data': None
     }
     self._work = True
開發者ID:SirEdvin,項目名稱:SpideLair,代碼行數:8,代碼來源:core.py

示例14: get_pactor_ref

 def get_pactor_ref(self):
     """Get a reference to a pykka actor for this."""
     if not self.is_active():
         raise NotRunningError("This game is not active.")
     else:
         actor_urn = cache.get(str(self.uuid))
         actor_ref = ActorRegistry.get_by_urn(actor_urn)
     return actor_ref
開發者ID:lexpar,項目名稱:CTeam,代碼行數:8,代碼來源:game_instance.py

示例15: test_write

 def test_write(self):  # pylint: disable=R0201
     """ Test writing to a writable.  """
     mock_open = flexmock(sys.modules['__builtin__'])
     mock_open.should_call('open')
     (mock_open.should_receive('open')
      .with_args('newfile', 'wb')
      .and_return(
          flexmock(write=lambda x: None)
          .should_receive('write').with_args('READY').once().mock()
          .should_receive('flush').once().mock()
          .should_receive('close').once().mock()
          )
      )
     wr = FileWriter('newfile')
     c = Collector.start(self.controller, wr)
     c.tell(Record(None, 'READY'))
     ActorRegistry.stop_all()
開發者ID:spacelis,項目名稱:crawler.kka,代碼行數:17,代碼來源:test_actors.py


注:本文中的pykka.ActorRegistry類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。