def restart_apps(self, config, loop, manager):
        if not os.path.isdir(config.plugin_dir):
            # the new plugin dir isn't found
            logging.error("config error plugging dir %r not found" %
                    config.plugin_dir)

            if self.plugin_dir != config.plugin_dir:
                logging.info("stop all current plugins")
                self.stop_apps()
            return

        # save all states
        old_plugins = self.plugins.copy()
        old_installed = self.installed
        old_apps = copy.copy(self.apps)
        old_plugin_dir = self.plugin_dir

        # scan the plugin dir
        self.plugin_dir = config.plugin_dir
        self.scan()

        try:
            self.check_mandatory()
        except __HOLE__ as e:
            # one dependency is missing, return
            logging.error("Failed to reload plugins: %s" % str(e))

            if self.plugin_dir != old_plugin_dir:
                logging.info("stop all current plugins")
                self.stop_apps()

            # reset values
            self.plugin_dir = old_plugin_dir
            self.plugins = old_plugins
            self.installed = old_installed
            self.apps = old_apps
            return

        # initialize new apps
        apps = self.init_apps(config)

        # stop removed plugins
        for ap in old_apps:
            if ap not in apps:
                app, _ = ap
                try:
                    app.stop()
                except Exception:
                     # we ignore all exception
                    logging.error('Uncaught exception when stopping a plugin',
                        exc_info=True)

        # start or restart plugins
        for app, plug in apps:
            try:
                if (app, plug) in old_apps:
                    app.restart()
                else:
                    app.start(loop, manager)
            except Exception:
                # we ignore all exception
                logging.error('Uncaught exception when (re)starting a plugin',
                        exc_info=True)
dataset/ETHPy150Open benoitc/gaffer/gaffer/gafferd/plugins.py/PluginManager.restart_apps