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


Python ActorRegistry.stop_all方法代码示例

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


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

示例1: _actor_loop

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
    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,代码行数:59,代码来源:_actor.py

示例2: test_fail

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
    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,代码行数:13,代码来源:test_actors.py

示例3: test_work

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
    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,代码行数:17,代码来源:test_actors.py

示例4: test_write

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
 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,代码行数:19,代码来源:test_actors.py

示例5: test_stop_all_stops_last_started_actor_first_if_blocking

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
    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,代码行数:19,代码来源:registry_test.py

示例6: main

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
def main():
    parser = argparse.ArgumentParser(
        description='Akka Spider')
    parser.add_argument('url',
                        help='URL seed, main url')

    parser.add_argument('-R', '--recursive-out-domain', action="store_true",
                        help='Continue recursion out of the domain')
    parser.add_argument('--ndownloaders', type=int, default=4, help='Number of downloaders')
    parser.add_argument('-w', '--write',  default='output.dot', help='Output file')
    args = parser.parse_args()

    if urlparse(args.url).scheme == '':
        raise Exception('Input url should contain scheme')
        return
    else:
        seed = [(args.url, args.url)]


    # Start actors
    queue = Queue.start().proxy()
    downloaders = map(
        lambda x: Downloader.start(queue).proxy()
        , range(args.ndownloaders))

    for url in seed:
        queue.push(url).get()

    if args.recursive_out_domain:
        exclusion_filter = lambda url: True
    else:
        exclusion_filter = lambda url: urlparse(url).netloc.endswith(urlparse(args.url).netloc)

    dot = scheduler(queue,
                    downloaders,
                    lambda: random.randrange(len(downloaders)),
                    exclusion_filter)

    with open(args.write, 'w') as f:
        f.write(dot.source)

    # Clean up
    ActorRegistry.stop_all()
开发者ID:pegerto,项目名称:akka-spider,代码行数:45,代码来源:spider.py

示例7: test_stop_all_stops_last_started_actor_first_if_blocking

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
def test_stop_all_stops_last_started_actor_first_if_blocking(mocker):
    mocker.patch.object(ActorRegistry, 'get_all')

    stopped_actors = []
    started_actors = [mocker.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)

    assert stopped_actors[0] == started_actors[2]
    assert stopped_actors[1] == started_actors[1]
    assert stopped_actors[2] == started_actors[0]
开发者ID:jodal,项目名称:pykka,代码行数:23,代码来源:test_registry.py

示例8: test_fatalfailwork

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
    def test_fatalfailwork(self):
        class Worker(object):
            def __init__(self, arg):
                self.arg = arg

            def work_on(self, task):
                pass

        ctl = (flexmock(tell=lambda x: None)
               .should_receive('tell').once()
               .with_args(Resignition).mock())

        (flexmock(Worker, work_on=lambda x: None)
         .should_receive('work_on').once()
         .with_args(1).and_raise(ValueError()))

        cr = Crawler.start(ctl, self.tasksource, self.collector,
                           Worker, self.initargs)
        cr.tell(Task(None, 1))
        cr.stop()
        ActorRegistry.stop_all()
开发者ID:spacelis,项目名称:crawler.kka,代码行数:23,代码来源:test_actors.py

示例9: test_all_actors_can_be_stopped_through_registry

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
 def test_all_actors_can_be_stopped_through_registry(self):
     self.assertEquals(9, len(ActorRegistry.get_all()))
     ActorRegistry.stop_all(block=True)
     self.assertEquals(0, len(ActorRegistry.get_all()))
开发者ID:0xD3ADB33F,项目名称:pykka,代码行数:6,代码来源:registry_test.py

示例10: tearDown

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
 def tearDown(self):
     ActorRegistry.stop_all()
开发者ID:0xD3ADB33F,项目名称:pykka,代码行数:4,代码来源:registry_test.py

示例11: tearDown

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
 def tearDown(self):
     self.log_handler.close()
     ActorRegistry.stop_all()
开发者ID:0xD3ADB33F,项目名称:pykka,代码行数:5,代码来源:logging_test.py

示例12: tearDownClass

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
 def tearDownClass(cls):
   ActorRegistry.stop_all()
开发者ID:areski,项目名称:freepy,代码行数:4,代码来源:server_tests.py

示例13: test_all_actors_can_be_stopped_through_registry

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
def test_all_actors_can_be_stopped_through_registry(a_actor_refs, b_actor_refs):
    assert len(ActorRegistry.get_all()) == 8

    ActorRegistry.stop_all(block=True)

    assert len(ActorRegistry.get_all()) == 0
开发者ID:jodal,项目名称:pykka,代码行数:8,代码来源:test_registry.py

示例14: range

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
    for _ in range(10000):
        actor.foo.get()


def test_direct_callable_attribute_access():
    actor = AnActor.start().proxy()
    for _ in range(10000):
        actor.func().get()


def test_traversable_plain_attribute_access():
    actor = AnActor.start().proxy()
    for _ in range(10000):
        actor.bar.cat.get()


def test_traversable_callable_attribute_access():
    actor = AnActor.start().proxy()
    for _ in range(10000):
        actor.bar.func().get()


if __name__ == '__main__':
    try:
        time_it(test_direct_plain_attribute_access)
        time_it(test_direct_callable_attribute_access)
        time_it(test_traversable_plain_attribute_access)
        time_it(test_traversable_callable_attribute_access)
    finally:
        ActorRegistry.stop_all()
开发者ID:jodal,项目名称:pykka,代码行数:32,代码来源:performance.py

示例15: stop

# 需要导入模块: from pykka import ActorRegistry [as 别名]
# 或者: from pykka.ActorRegistry import stop_all [as 别名]
 def stop(self):
   ActorRegistry.stop_all()
开发者ID:areski,项目名称:freepy,代码行数:4,代码来源:server.py


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