From 93058c3238e6c6a161a2e2d5fe87f292724d8017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorena=20B=C4=83lan?= Date: Wed, 21 Oct 2020 10:38:16 +0100 Subject: [PATCH] [KED-2171] Fix IPython init script bug causing hooks to be registered twice (#832) --- .../.ipython/profile_default/startup/00-kedro-init.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kedro/templates/project/{{ cookiecutter.repo_name }}/.ipython/profile_default/startup/00-kedro-init.py b/kedro/templates/project/{{ cookiecutter.repo_name }}/.ipython/profile_default/startup/00-kedro-init.py index a0f53d1584..dfa1781cd3 100644 --- a/kedro/templates/project/{{ cookiecutter.repo_name }}/.ipython/profile_default/startup/00-kedro-init.py +++ b/kedro/templates/project/{{ cookiecutter.repo_name }}/.ipython/profile_default/startup/00-kedro-init.py @@ -3,6 +3,7 @@ from pathlib import Path from IPython.core.magic import register_line_magic, needs_local_scope +from kedro.framework.hooks import get_hook_manager # Find the project root (./../../../) startup_error = None @@ -38,6 +39,13 @@ def reload_kedro(path, line=None): for module in to_remove: del sys.modules[module] + # clear hook manager; hook implementations will be re-registered when the + # context is instantiated again in `load_context()` below + hook_manager = get_hook_manager() + name_plugin_pairs = hook_manager.list_name_plugin() + for name, plugin in name_plugin_pairs: + hook_manager.unregister(name=name, plugin=plugin) + logging.debug("Loading the context from %s", str(path)) # Reload context to fix `pickle` related error (it is unable to serialize reloaded objects) # Some details can be found here: