-
Notifications
You must be signed in to change notification settings - Fork 908
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Streamline debugging documentation (#3608)
* Add first draft Signed-off-by: lrcouto <[email protected]> * Remoe outdated kedro jupyter convert docs Signed-off-by: Ahdra Merali <[email protected]> * Suggestion: Review edits Signed-off-by: Ahdra Merali <[email protected]> * Update FAQs Signed-off-by: Ahdra Merali <[email protected]> * Edit jupyter ipython debug section Signed-off-by: lrcouto <[email protected]> * Change link to section that does not exist anymore Signed-off-by: L. R. Couto <[email protected]> * Change link to section that does not exist anymore Signed-off-by: L. R. Couto <[email protected]> * Change wording and formatting Signed-off-by: lrcouto <[email protected]> * Lint Signed-off-by: lrcouto <[email protected]> * Update docs/source/notebooks_and_ipython/kedro_and_notebooks.md Co-authored-by: Jo Stichbury <[email protected]> Signed-off-by: L. R. Couto <[email protected]> * Update docs/source/notebooks_and_ipython/kedro_and_notebooks.md Co-authored-by: Ahdra Merali <[email protected]> Signed-off-by: L. R. Couto <[email protected]> * Changes to the wording, remove unnecessary section Signed-off-by: lrcouto <[email protected]> * Move docs on debugging with hooks to hooks section Signed-off-by: Ahdra Merali <[email protected]> * Add links to main debugging page Signed-off-by: Ahdra Merali <[email protected]> * Make notebook debugging an independent section Signed-off-by: Ahdra Merali <[email protected]> * Update link in FAQs Signed-off-by: Ahdra Merali <[email protected]> * Apply suggestions from code review - adjust wording Co-authored-by: Jo Stichbury <[email protected]> Signed-off-by: Ahdra Merali <[email protected]> * Capitalise Hooks Signed-off-by: Ahdra Merali <[email protected]> * Reorder links on debugging page Signed-off-by: Ahdra Merali <[email protected]> * Use markdown admonitions Signed-off-by: Ahdra Merali <[email protected]> * Add short explanations to debugging page Signed-off-by: Ahdra Merali <[email protected]> --------- Signed-off-by: lrcouto <[email protected]> Signed-off-by: Ahdra Merali <[email protected]> Signed-off-by: Ahdra Merali <[email protected]> Signed-off-by: L. R. Couto <[email protected]> Signed-off-by: L. R. Couto <[email protected]> Co-authored-by: lrcouto <[email protected]> Co-authored-by: L. R. Couto <[email protected]> Co-authored-by: Jo Stichbury <[email protected]>
- Loading branch information
1 parent
f54c6fb
commit 80ad182
Showing
4 changed files
with
90 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,12 @@ | ||
# Debugging | ||
|
||
## Introduction | ||
:::note | ||
|
||
If you're running your Kedro pipeline from the CLI or you can't/don't want to run Kedro from within your IDE debugging framework, it can be hard to debug your Kedro pipeline or nodes. This is particularly frustrating because: | ||
Our debugging documentation has moved. Please see our existing guides: | ||
|
||
* If you have long running nodes or pipelines, inserting `print` statements and running them multiple times quickly becomes time-consuming. | ||
* Debugging nodes outside the `run` session isn't very helpful because getting access to the local scope within the `node` can be hard, especially if you're dealing with large data or memory datasets, where you need to chain a few nodes together or re-run your pipeline to produce the data for debugging purposes. | ||
::: | ||
|
||
This guide provides examples on [how to instantiate a post-mortem debugging session](https://docs.python.org/3/library/pdb.html#pdb.post_mortem) with [`pdb`](https://docs.python.org/3/library/pdb.html) using [Kedro Hooks](../hooks/introduction.md) when an uncaught error occurs during a pipeline run. [ipdb](https://pypi.org/project/ipdb/) could be integrated in the same manner. | ||
|
||
For guides on how to set up debugging with IDEs, please visit the [guide for debugging in VSCode](./set_up_vscode.md#debugging) and the [guide for debugging in PyCharm](./set_up_pycharm.md#debugging). | ||
|
||
## Debugging a node | ||
|
||
To start a debugging session when an uncaught error is raised within your `node`, implement the `on_node_error` [Hook specification](/api/kedro.framework.hooks): | ||
|
||
```python | ||
import pdb | ||
import sys | ||
import traceback | ||
|
||
from kedro.framework.hooks import hook_impl | ||
|
||
|
||
class PDBNodeDebugHook: | ||
"""A hook class for creating a post mortem debugging with the PDB debugger | ||
whenever an error is triggered within a node. The local scope from when the | ||
exception occured is available within this debugging session. | ||
""" | ||
|
||
@hook_impl | ||
def on_node_error(self): | ||
_, _, traceback_object = sys.exc_info() | ||
|
||
# Print the traceback information for debugging ease | ||
traceback.print_tb(traceback_object) | ||
|
||
# Drop you into a post mortem debugging session | ||
pdb.post_mortem(traceback_object) | ||
``` | ||
|
||
You can then register this `PDBNodeDebugHook` in your project's `settings.py`: | ||
|
||
```python | ||
HOOKS = (PDBNodeDebugHook(),) | ||
``` | ||
|
||
## Debugging a pipeline | ||
|
||
To start a debugging session when an uncaught error is raised within your `pipeline`, implement the `on_pipeline_error` [Hook specification](/api/kedro.framework.hooks): | ||
|
||
```python | ||
import pdb | ||
import sys | ||
import traceback | ||
|
||
from kedro.framework.hooks import hook_impl | ||
|
||
|
||
class PDBPipelineDebugHook: | ||
"""A hook class for creating a post mortem debugging with the PDB debugger | ||
whenever an error is triggered within a pipeline. The local scope from when the | ||
exception occured is available within this debugging session. | ||
""" | ||
|
||
@hook_impl | ||
def on_pipeline_error(self): | ||
# We don't need the actual exception since it is within this stack frame | ||
_, _, traceback_object = sys.exc_info() | ||
|
||
# Print the traceback information for debugging ease | ||
traceback.print_tb(traceback_object) | ||
|
||
# Drop you into a post mortem debugging session | ||
pdb.post_mortem(traceback_object) | ||
``` | ||
|
||
You can then register this `PDBPipelineDebugHook` in your project's `settings.py`: | ||
|
||
```python | ||
HOOKS = (PDBPipelineDebugHook(),) | ||
``` | ||
* [Debugging a Kedro project within a notebook](../notebooks_and_ipython/kedro_and_notebooks.md#debugging-a-kedro-project-within-a-notebook) for information on how to launch an interactive debugger in your notebook. | ||
* [Debugging in VSCode](./set_up_vscode.md#debugging) for information on how to set up VSCode's built-in debugger. | ||
* [Debugging in PyCharm](./set_up_pycharm.md#debugging) for information on using PyCharm's debugging tool. | ||
* [Debugging in the CLI with Kedro Hooks](../hooks/common_use_cases.md#use-hooks-to-debug-your-pipeline) for information on how to automatically launch an interactive debugger in the CLI when an error occurs in your pipeline run. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters