Exemple #1
0
    async def shutdown(self) -> None:
        """
        Asynchronously shut down all running plugins. Raises an
        :class:`~trinity.extensibility.exceptions.UnsuitableShutdownError` if called on a
        :class:`~trinity.extensibility.plugin_manager.PluginManager` that operates in the
        :class:`~trinity.extensibility.plugin_manager.MainAndIsolatedProcessScope`.
        """
        if isinstance(self._scope, MainAndIsolatedProcessScope):
            raise UnsuitableShutdownError(
                "Use `shutdown_blocking` for instances of this scope")

        self._logger.info("Shutting down PluginManager with scope %s",
                          type(self._scope))

        async_plugins = [
            plugin for plugin in self._plugin_store
            if isinstance(plugin, BaseAsyncStopPlugin) and plugin.running
        ]

        stop_results = await asyncio.gather(*self._stop_plugins(async_plugins),
                                            return_exceptions=True)

        for plugin, result in zip(async_plugins, stop_results):
            if isinstance(result, Exception):
                self._logger.error(
                    'Exception thrown while stopping plugin %s: %s',
                    plugin.name, result)
            else:
                self._logger.info("Successfully stopped plugin: %s",
                                  plugin.name)
Exemple #2
0
    def shutdown_blocking(self) -> None:
        """
        Synchronously shut down all running plugins. Raises an
        :class:`~trinity.extensibility.exceptions.UnsuitableShutdownError` if called on a
        :class:`~trinity.extensibility.plugin_manager.PluginManager` that operates in the
        :class:`~trinity.extensibility.plugin_manager.SharedProcessScope`.
        """

        if isinstance(self._scope, SharedProcessScope):
            raise UnsuitableShutdownError(
                "Use `shutdown` for instances of this scope")

        self._logger.info("Shutting down PluginManager with scope %s",
                          type(self._scope))

        plugins = [
            plugin for plugin in self._plugin_store
            if isinstance(plugin, BaseIsolatedPlugin) and plugin.running
        ]
        processes = [plugin.process for plugin in plugins]

        for plugin in plugins:
            self._logger.info("Stopping plugin: %s", plugin.name)

        kill_processes_gracefully(processes, self._logger)

        for plugin in plugins:
            self._logger.info("Successfully stopped plugin: %s", plugin.name)
Exemple #3
0
    def shutdown_blocking(self) -> None:
        """
        Synchronously shut down all running plugins. Raises an
        :class:`~trinity.extensibility.exceptions.UnsuitableShutdownError` if called on a
        :class:`~trinity.extensibility.plugin_manager.PluginManager` that operates in the
        :class:`~trinity.extensibility.plugin_manager.SharedProcessScope`.
        """

        if isinstance(self._scope, SharedProcessScope):
            raise UnsuitableShutdownError(
                "Use `shutdown` for instances of this scope")

        self._logger.info("Shutting down PluginManager with scope %s",
                          type(self._scope))

        for plugin in self._plugin_store:

            if not isinstance(plugin,
                              BaseSyncStopPlugin) or not plugin.running:
                continue

            try:
                self._logger.info("Stopping plugin: %s", plugin.name)
                plugin.stop()
                self._logger.info("Successfully stopped plugin: %s",
                                  plugin.name)
            except Exception:
                self._logger.exception(
                    "Exception thrown while stopping plugin %s", plugin.name)
Exemple #4
0
    async def shutdown(self) -> None:
        """
        Asynchronously shut down all started plugins.
        """

        if isinstance(self._scope, MainAndIsolatedProcessScope):
            raise UnsuitableShutdownError("Use `shutdown_blocking` for instances of this scope")

        self._logger.info("Shutting down PluginManager with scope %s", type(self._scope))

        async_plugins = [
            plugin for plugin in self._started_plugins
            if isinstance(plugin, BaseAsyncStopPlugin)
        ]

        stop_results = await asyncio.gather(
            *self._stop_plugins(async_plugins), return_exceptions=True
        )

        for plugin, result in zip(async_plugins, stop_results):
            if isinstance(result, Exception):
                self._logger.error(
                    'Exception thrown while stopping plugin %s: %s', plugin.name, result
                )
            else:
                self._logger.info("Successfully stopped plugin: %s", plugin.name)
Exemple #5
0
    def shutdown_blocking(self) -> None:
        """
        Synchronously shut down all started plugins.
        """

        if isinstance(self._scope, SharedProcessScope):
            raise UnsuitableShutdownError(
                "Use `shutdown` for instances of this scope")

        self._logger.info("Shutting down PluginManager with scope %s",
                          type(self._scope))

        for plugin in self._started_plugins:

            if not isinstance(plugin, BaseSyncStopPlugin):
                continue

            try:
                self._logger.info("Stopping plugin: %s", plugin.name)
                plugin.stop()
                self._logger.info("Successfully stopped plugin: %s",
                                  plugin.name)
            except Exception:
                self._logger.exception(
                    "Exception thrown while stopping plugin %s", plugin.name)