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


Python ServiceRunner.stop方法代碼示例

本文整理匯總了Python中nameko.runners.ServiceRunner.stop方法的典型用法代碼示例。如果您正苦於以下問題:Python ServiceRunner.stop方法的具體用法?Python ServiceRunner.stop怎麽用?Python ServiceRunner.stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nameko.runners.ServiceRunner的用法示例。


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

示例1: main

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
def main():
    config = {
        '_log': LOG,
        'AMQP_URI': 'amqp://guest:[email protected]:5672'
    }
    service_runner = ServiceRunner(config)
    service_runner.add_service(DatabaseService)

    service_runner.start()

    runnlet = eventlet.spawn(service_runner.wait)

    while True:
        try:
            runnlet.wait()
        except OSError as exc:
            if exc.errno == errno.EINTR:
                continue
            raise
        except KeyboardInterrupt:
            try:
                service_runner.stop()
            except KeyboardInterrupt:
                service_runner.kill()
        else:
            break
開發者ID:felippemr,項目名稱:python_zookeeper_lock,代碼行數:28,代碼來源:database_service.py

示例2: service_container

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
def service_container(patched_db):
    config = {'AMQP_URI': settings.NAMEKO_AMQP_URI}
    runner = ServiceRunner(config)
    runner.add_service(NamekoCollectionService)
    runner.start()

    container = get_container(runner, NamekoCollectionService)
    yield container

    runner.stop()
開發者ID:turc42,項目名稱:pylytics,代碼行數:12,代碼來源:test_nameko.py

示例3: test_runner_lifecycle

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
def test_runner_lifecycle(fake_module):
    events = set()

    class Container(object):
        def __init__(self, service_cls, config):
            self.service_name = service_cls.__name__
            self.service_cls = service_cls

        def start(self):
            events.add(('start', self.service_cls.name, self.service_cls))

        def stop(self):
            events.add(('stop', self.service_cls.name, self.service_cls))

        def kill(self):
            events.add(('kill', self.service_cls.name, self.service_cls))

        def wait(self):
            events.add(('wait', self.service_cls.name, self.service_cls))

    fake_module.ServiceContainer = Container

    config = {'SERVICE_CONTAINER_CLS': 'fake_module.ServiceContainer'}
    runner = ServiceRunner(config)

    runner.add_service(TestService1)
    runner.add_service(TestService2)

    runner.start()

    assert events == {
        ('start', 'foobar_1', TestService1),
        ('start', 'foobar_2', TestService2),
    }

    events = set()
    runner.stop()
    assert events == {
        ('stop', 'foobar_1', TestService1),
        ('stop', 'foobar_2', TestService2),
    }

    events = set()
    runner.kill()
    assert events == {
        ('kill', 'foobar_1', TestService1),
        ('kill', 'foobar_2', TestService2),
    }

    events = set()
    runner.wait()
    assert events == {
        ('wait', 'foobar_1', TestService1),
        ('wait', 'foobar_2', TestService2),
    }
開發者ID:davidszotten,項目名稱:nameko,代碼行數:57,代碼來源:test_service_runner.py

示例4: test_runner_lifecycle

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
def test_runner_lifecycle():
    events = set()

    class Container(object):
        def __init__(self, service_cls, worker_ctx_cls, config):
            self.service_name = service_cls.__name__
            self.service_cls = service_cls
            self.worker_ctx_cls = worker_ctx_cls

        def start(self):
            events.add(('start', self.service_cls.name, self.service_cls))

        def stop(self):
            events.add(('stop', self.service_cls.name, self.service_cls))

        def kill(self):
            events.add(('kill', self.service_cls.name, self.service_cls))

        def wait(self):
            events.add(('wait', self.service_cls.name, self.service_cls))

    config = {}
    runner = ServiceRunner(config, container_cls=Container)

    runner.add_service(TestService1)
    runner.add_service(TestService2)

    runner.start()

    assert events == {
        ('start', 'foobar_1', TestService1),
        ('start', 'foobar_2', TestService2),
    }

    events = set()
    runner.stop()
    assert events == {
        ('stop', 'foobar_1', TestService1),
        ('stop', 'foobar_2', TestService2),
    }

    events = set()
    runner.kill()
    assert events == {
        ('kill', 'foobar_1', TestService1),
        ('kill', 'foobar_2', TestService2),
    }

    events = set()
    runner.wait()
    assert events == {
        ('wait', 'foobar_1', TestService1),
        ('wait', 'foobar_2', TestService2),
    }
開發者ID:ahmb,項目名稱:nameko,代碼行數:56,代碼來源:test_service_runner.py

示例5: main

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
def main():
    import logging
    logging.basicConfig(level=logging.DEBUG)

    config = {'AMQP_URI': 'amqp://guest:[email protected]:5672/'}
    runner = ServiceRunner(config)
    runner.add_service(MessagingPublisher)
    runner.start()

    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.stop()
開發者ID:ahmb,項目名稱:nameko,代碼行數:15,代碼來源:messaging_publisher.py

示例6: test_service_integration

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
def test_service_integration():
    config = {"AMQP_URI": "amqp://guest:[email protected]:5672/"}
    runner = ServiceRunner(config)
    runner.add_service(ServiceX)
    runner.add_service(ServiceY)
    runner.start()

    container = get_container(runner, ServiceX)

    with entrypoint_hook(container, "remote_method") as entrypoint:
        assert entrypoint("value") == "value-x-y"

    runner.stop()
開發者ID:pombredanne,項目名稱:nameko,代碼行數:15,代碼來源:integration_test.py

示例7: main

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
def main():

    logging.basicConfig(level=logging.DEBUG)

    config = {'AMQP_URI': 'amqp://guest:[email protected]:5672/'}
    runner = ServiceRunner(config)
    runner.add_service(HelloWorld)
    runner.add_service(FriendlyService)
    runner.start()
    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.stop()
開發者ID:ahmb,項目名稱:nameko,代碼行數:15,代碼來源:helloworld.py

示例8: main

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
def main():
    config_dict = get_config_yaml(CONFIG_YAML_PATH)
    c = update_config_yaml(config_dict, CONFIG_YAML_PATH)
    wus = WatchURLService()
    wus.get_config()
    runner = ServiceRunner(c)
    runner.add_service(WatchURLService)
    # container_a = get_container(runner, WatchURLService)
    runner.start()
    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.kill()
    runner.stop()
開發者ID:juga0,項目名稱:watch-url,代碼行數:16,代碼來源:watch_pages_tos_service.py

示例9: main

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
def main():

    logging.basicConfig(level=logging.DEBUG)

    # disable most logging so we can see the console
    logger = logging.getLogger("")
    logger.setLevel(logging.WARNING)

    config = {"AMQP_URI": "amqp://guest:[email protected]:5672/chat"}
    runner = ServiceRunner(config)
    runner.add_service(Chat)
    runner.start()
    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.stop()
開發者ID:pbowyer,項目名稱:nameko-chat,代碼行數:18,代碼來源:service.py

示例10: test_service_x_y_integration

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
def test_service_x_y_integration():

    # run services in the normal manner
    config = {'AMQP_URI': 'amqp://guest:[email protected]:5672/'}
    runner = ServiceRunner(config)
    runner.add_service(ServiceX)
    runner.add_service(ServiceY)
    runner.start()

    # artificially fire the "remote_method" entrypoint on ServiceX
    # and verify response
    container = get_container(runner, ServiceX)
    with entrypoint_hook(container, "remote_method") as entrypoint:
        assert entrypoint("value") == "value-x-y"

    runner.stop()
開發者ID:davinirjr,項目名稱:nameko,代碼行數:18,代碼來源:integration_test.py

示例11: handle

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
    def handle(self, *args, **options):
        runner = ServiceRunner(settings.AMQP_CONFIG)
        runner.add_service(MasterService)

        def shutdown(signum, frame):
            eventlet.spawn_n(runner.kill)
        signal.signal(signal.SIGTERM, shutdown)

        runner.start()
        try:
            runner.wait()
        except KeyboardInterrupt:
            try:
                runner.stop()
            except KeyboardInterrupt:
                runner.kill()
開發者ID:amd77,項目名稱:parker,代碼行數:18,代碼來源:nameko_server_post.py

示例12: run

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
def run(services, config, backdoor_port=None):
    service_runner = ServiceRunner(config)
    for service_cls in services:
        service_runner.add_service(service_cls)

    def shutdown(signum, frame):
        # signal handlers are run by the MAINLOOP and cannot use eventlet
        # primitives, so we have to call `stop` in a greenlet
        eventlet.spawn_n(service_runner.stop)

    signal.signal(signal.SIGTERM, shutdown)

    if backdoor_port is not None:
        setup_backdoor(service_runner, backdoor_port)

    service_runner.start()

    # if the signal handler fires while eventlet is waiting on a socket,
    # the __main__ greenlet gets an OSError(4) "Interrupted system call".
    # This is a side-effect of the eventlet hub mechanism. To protect nameko
    # from seeing the exception, we wrap the runner.wait call in a greenlet
    # spawned here, so that we can catch (and silence) the exception.
    runnlet = eventlet.spawn(service_runner.wait)

    while True:
        try:
            runnlet.wait()
        except OSError as exc:
            if exc.errno == errno.EINTR:
                # this is the OSError(4) caused by the signalhandler.
                # ignore and go back to waiting on the runner
                continue
            raise
        except KeyboardInterrupt:
            print()  # looks nicer with the ^C e.g. bash prints in the terminal
            try:
                service_runner.stop()
            except KeyboardInterrupt:
                print()  # as above
                service_runner.kill()
        else:
            # runner.wait completed
            break
開發者ID:sohonetlabs,項目名稱:nameko,代碼行數:45,代碼來源:run.py

示例13: run_nameko

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
def run_nameko(args):
    # Running nameko imports here so that Eventgen as a module does not require nameko to run.
    import eventlet
    eventlet.monkey_patch()
    from nameko.runners import ServiceRunner
    # In order to make this run locally as well as within a container-ized environment, we're to pull variables
    # from both environment variables and CLI arguments, where CLI will take precendence.
    config = parse_env_vars()
    config = parse_cli_vars(config, args)
    config = rectify_config(config)
    print "Config used: {}".format(config)
    # Wait up to 30s for RMQ service to be up
    wait_for_response(config["AMQP_URI"], config["AMQP_WEBPORT"])
    # Start Nameko service
    runner = ServiceRunner(config=config)
    if args.role == "controller":
        from eventgen_nameko_controller import EventgenController
        runner.add_service(EventgenController)
    else:
        from eventgen_nameko_server import EventgenServer
        runner.add_service(EventgenServer)
    runner.start()
    runnlet = eventlet.spawn(runner.wait)
    while True:
        try:
            runnlet.wait()
        except OSError as exc:
            if exc.errno == errno.EINTR:
                # this is the OSError(4) caused by the signalhandler.
                # ignore and go back to waiting on the runner
                continue
            raise
        except KeyboardInterrupt:
            print()  # looks nicer with the ^C e.g. bash prints in the terminal
            try:
                runner.stop()
            except KeyboardInterrupt:
                print()  # as above
                runner.kill()
        else:
            # runner.wait completed
            break
開發者ID:splunk,項目名稱:eventgen,代碼行數:44,代碼來源:__main__.py

示例14: run

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
def run():
    config = {'AMQP_URI': 'amqp://localhost'}
    runner = ServiceRunner(config)
    runner.add_service(AlarmService)
    runner.add_service(HttpEntrypointService)
    runner.add_service(LightService)
    runner.add_service(LocalStorageService)
    runner.add_service(SpotifyService)
    runner.add_service(VolumeService)
    runner.start()

    runnlet = eventlet.spawn(runner.wait)

    try:
        runnlet.wait()
    except KeyboardInterrupt:
        try:
            runner.stop()
        except KeyboardInterrupt:
            runner.kill()
開發者ID:miguelfrde,項目名稱:roomcontrol_backend,代碼行數:22,代碼來源:roomcontrol.py

示例15: ServiceA

# 需要導入模塊: from nameko.runners import ServiceRunner [as 別名]
# 或者: from nameko.runners.ServiceRunner import stop [as 別名]
from nameko.runners import ServiceRunner
from nameko.utils import get_container


class ServiceA(object):
    name = "service_a"


class ServiceB(object):
    name = "service_b"


# create a runner for ServiceA and ServiceB
runner = ServiceRunner(config={})
runner.add_service(ServiceA)
runner.add_service(ServiceB)

# ``get_container`` will return the container for a particular service
container_a = get_container(runner, ServiceA)

# start both services
runner.start()

# stop both services
runner.stop()
開發者ID:mamachanko,項目名稱:nameko,代碼行數:27,代碼來源:service_runner.py


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