示例#1
0
    def __init__(self, service_cls, config, worker_ctx_cls=None):

        self.service_cls = service_cls
        self.config = config

        if worker_ctx_cls is not None:
            warnings.warn(
                "The constructor of `ServiceContainer` has changed. "
                "The `worker_ctx_cls` kwarg is now deprecated. See CHANGES, "
                "version 2.4.0 for more details. This warning will be removed "
                "in version 2.6.0", DeprecationWarning
            )
        else:
            worker_ctx_cls = WorkerContext

        self.worker_ctx_cls = worker_ctx_cls

        self.service_name = get_service_name(service_cls)
        self.shared_extensions = {}

        self.max_workers = (
            config.get(MAX_WORKERS_CONFIG_KEY) or DEFAULT_MAX_WORKERS)

        self.serializer = config.get(
            SERIALIZER_CONFIG_KEY, DEFAULT_SERIALIZER)

        self.accept = [self.serializer]

        self.entrypoints = SpawningSet()
        self.dependencies = SpawningSet()
        self.subextensions = SpawningSet()

        for attr_name, dependency in inspect.getmembers(service_cls,
                                                        is_dependency):
            bound = dependency.bind(self.interface, attr_name)
            self.dependencies.add(bound)
            self.subextensions.update(iter_extensions(bound))

        for method_name, method in inspect.getmembers(service_cls, is_method):
            entrypoints = getattr(method, ENTRYPOINT_EXTENSIONS_ATTR, [])
            for entrypoint in entrypoints:
                bound = entrypoint.bind(self.interface, method_name)
                self.entrypoints.add(bound)
                self.subextensions.update(iter_extensions(bound))

        self.started = False
        self._worker_pool = GreenPool(size=self.max_workers)

        self._worker_threads = {}
        self._managed_threads = {}
        self._being_killed = False
        self._died = Event()
示例#2
0
    def __init__(self, service_cls, config, worker_ctx_cls=None):

        self.service_cls = service_cls
        self.config = config

        if worker_ctx_cls is not None:
            warnings.warn(
                "The constructor of `ServiceContainer` has changed. "
                "The `worker_ctx_cls` kwarg is now deprecated. See CHANGES, "
                "version 2.4.0 for more details. This warning will be removed "
                "in version 2.6.0", DeprecationWarning)
        else:
            worker_ctx_cls = WorkerContext

        self.worker_ctx_cls = worker_ctx_cls

        self.service_name = get_service_name(service_cls)
        self.shared_extensions = {}

        self.max_workers = (config.get(MAX_WORKERS_CONFIG_KEY)
                            or DEFAULT_MAX_WORKERS)

        self.serializer = config.get(SERIALIZER_CONFIG_KEY, DEFAULT_SERIALIZER)

        self.accept = [self.serializer]

        self.entrypoints = SpawningSet()
        self.dependencies = SpawningSet()
        self.subextensions = SpawningSet()

        for attr_name, dependency in inspect.getmembers(
                service_cls, is_dependency):
            bound = dependency.bind(self.interface, attr_name)
            self.dependencies.add(bound)
            self.subextensions.update(iter_extensions(bound))

        for method_name, method in inspect.getmembers(service_cls, is_method):
            entrypoints = getattr(method, ENTRYPOINT_EXTENSIONS_ATTR, [])
            for entrypoint in entrypoints:
                bound = entrypoint.bind(self.interface, method_name)
                self.entrypoints.add(bound)
                self.subextensions.update(iter_extensions(bound))

        self.started = False
        self._worker_pool = GreenPool(size=self.max_workers)

        self._worker_threads = {}
        self._managed_threads = {}
        self._being_killed = False
        self._died = Event()
示例#3
0
    def __init__(self, service_cls, config, worker_ctx_cls=None):

        self.service_cls = service_cls
        self.config = config

        if worker_ctx_cls is None:
            worker_ctx_cls = WorkerContext
        self.worker_ctx_cls = worker_ctx_cls

        self.service_name = get_service_name(service_cls)
        self.shared_extensions = {}

        self.max_workers = (
            config.get(MAX_WORKERS_CONFIG_KEY) or DEFAULT_MAX_WORKERS)

        self.serializer = config.get(
            SERIALIZER_CONFIG_KEY, DEFAULT_SERIALIZER)

        self.accept = [self.serializer]

        self.entrypoints = SpawningSet()
        self.dependencies = SpawningSet()
        self.subextensions = SpawningSet()

        for attr_name, dependency in inspect.getmembers(service_cls,
                                                        is_dependency):
            bound = dependency.bind(self.interface, attr_name)
            self.dependencies.add(bound)
            self.subextensions.update(iter_extensions(bound))

        for method_name, method in inspect.getmembers(service_cls, is_method):
            entrypoints = getattr(method, ENTRYPOINT_EXTENSIONS_ATTR, [])
            for entrypoint in entrypoints:
                bound = entrypoint.bind(self.interface, method_name)
                self.entrypoints.add(bound)
                self.subextensions.update(iter_extensions(bound))

        self.started = False
        self._worker_pool = GreenPool(size=self.max_workers)

        self._active_threads = {}
        self._protected_threads = set()
        self._being_killed = False
        self._died = Event()
示例#4
0
    def __init__(self, service_cls, config, worker_ctx_cls=None):

        self.service_cls = service_cls
        self.config = config

        if worker_ctx_cls is None:
            worker_ctx_cls = WorkerContext
        self.worker_ctx_cls = worker_ctx_cls

        self.service_name = get_service_name(service_cls)
        self.shared_extensions = {}

        self.max_workers = (config.get(MAX_WORKERS_CONFIG_KEY)
                            or DEFAULT_MAX_WORKERS)

        self.serializer = config.get(SERIALIZER_CONFIG_KEY, DEFAULT_SERIALIZER)

        self.accept = [self.serializer]

        self.entrypoints = SpawningSet()
        self.dependencies = SpawningSet()
        self.subextensions = SpawningSet()

        for attr_name, dependency in inspect.getmembers(
                service_cls, is_dependency):
            bound = dependency.bind(self.interface, attr_name)
            self.dependencies.add(bound)
            self.subextensions.update(iter_extensions(bound))

        for method_name, method in inspect.getmembers(service_cls, is_method):
            entrypoints = getattr(method, ENTRYPOINT_EXTENSIONS_ATTR, [])
            for entrypoint in entrypoints:
                bound = entrypoint.bind(self.interface, method_name)
                self.entrypoints.add(bound)
                self.subextensions.update(iter_extensions(bound))

        self.started = False
        self._worker_pool = GreenPool(size=self.max_workers)

        self._active_threads = {}
        self._protected_threads = set()
        self._being_killed = False
        self._died = Event()
示例#5
0
    def __init__(self, service_cls_list, config):
        self.service_cls_list = service_cls_list
        self.config = config
        self.serializer, self.accept = serialization.setup(self.config)
        self.max_workers = (config.get(MAX_WORKERS_CONFIG_KEY)
                            or DEFAULT_MAX_WORKERS)

        self.shared_extensions = {}
        self.entrypoints = SpawningSet()
        self.dependencies = SpawningSet()
        self.subextensions = SpawningSet()

        self.started = False
        self._worker_pool = GreenPool(size=self.max_workers)

        self._worker_threads = {}
        self._managed_threads = {}
        self._being_killed = False
        self._died = Event()

        for service_cls in service_cls_list:
            self.service_cls = service_cls

            self.service_name = get_service_name(service_cls)

            for attr_name, dependency in inspect.getmembers(
                    service_cls, is_dependency):
                bound = dependency.bind(self.interface, attr_name)
                self.dependencies.add(bound)
                self.subextensions.update(iter_extensions(bound))

            for method_name, method in inspect.getmembers(
                    service_cls, is_method):
                entrypoints = getattr(method, ENTRYPOINT_EXTENSIONS_ATTR, [])
                for entrypoint in entrypoints:
                    bound = entrypoint.bind(self.interface, method_name)
                    self.entrypoints.add(bound)
                    self.subextensions.update(iter_extensions(bound))
示例#6
0
    def __init__(self, service_cls, config):

        self.service_cls = service_cls
        self.config = config

        self.service_name = get_service_name(service_cls)
        self.shared_extensions = {}

        self.max_workers = (
            config.get(MAX_WORKERS_CONFIG_KEY) or DEFAULT_MAX_WORKERS)

        self.serializer, self.accept = serialization.setup(self.config)

        self.entrypoints = SpawningSet()
        self.dependencies = SpawningSet()
        self.subextensions = SpawningSet()

        for attr_name, dependency in inspect.getmembers(service_cls,
                                                        is_dependency):
            bound = dependency.bind(self.interface, attr_name)
            self.dependencies.add(bound)
            self.subextensions.update(iter_extensions(bound))

        for method_name, method in inspect.getmembers(service_cls, is_method):
            entrypoints = getattr(method, ENTRYPOINT_EXTENSIONS_ATTR, [])
            for entrypoint in entrypoints:
                bound = entrypoint.bind(self.interface, method_name)
                self.entrypoints.add(bound)
                self.subextensions.update(iter_extensions(bound))

        self.started = False
        self._worker_pool = GreenPool(size=self.max_workers)

        self._worker_threads = {}
        self._managed_threads = {}
        self._being_killed = False
        self._died = Event()