From 3f98be163a94337b7f30836853915518ff98a79a Mon Sep 17 00:00:00 2001 From: Michael Chin Date: Tue, 7 Mar 2023 19:51:37 -0800 Subject: [PATCH 1/3] Fix nbextensions loader timeout on large notebooks --- src/graph_notebook/start_notebook.py | 31 ++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/graph_notebook/start_notebook.py b/src/graph_notebook/start_notebook.py index cd0f829b..65370abc 100644 --- a/src/graph_notebook/start_notebook.py +++ b/src/graph_notebook/start_notebook.py @@ -9,8 +9,10 @@ HOME_PATH = os.path.expanduser("~") NBCONFIG_DIR_TREE = HOME_PATH + '/.jupyter/nbconfig' -CFG_FILE_NAME = 'notebook.json' -NOTEBOOK_CFG_PATH = NBCONFIG_DIR_TREE + '/' + CFG_FILE_NAME +NOTEBOOK_CFG_PATH = NBCONFIG_DIR_TREE + '/notebook.json' + +CUSTOM_DIR_TREE = HOME_PATH + '/.jupyter/custom' +NOTEBOOK_CUSTOMJS_PATH = CUSTOM_DIR_TREE + '/custom.js' def patch_cm_cypher_config(): @@ -33,6 +35,30 @@ def patch_cm_cypher_config(): json.dump(notebook_cfg, file, indent=2) +def patch_customjs(): + # Increases time allotted to load nbextensions on large notebooks. Limit is set to 60s and can be increased further. + # Reference: https://github.com/ipython-contrib/jupyter_contrib_nbextensions/blob/master/docs/source/troubleshooting.md#extensions-not-loading-for-large-notebooks + limit = "60" + increase_requirejs_timeout_prefix = "window.requirejs.config({waitSeconds:" + increase_requirejs_timeout_suffix = "});" + requirejs_timeout_full = increase_requirejs_timeout_prefix + limit + increase_requirejs_timeout_suffix + + try: + os.makedirs(CUSTOM_DIR_TREE, exist_ok=True) + with open(NOTEBOOK_CUSTOMJS_PATH, 'r') as file: + customjs_content = file.read() + except (json.decoder.JSONDecodeError, FileNotFoundError) as e: + customjs_content = "" + + if increase_requirejs_timeout_prefix not in customjs_content: + if customjs_content: + customjs_content += "\n" + customjs_content += requirejs_timeout_full + with open(NOTEBOOK_CUSTOMJS_PATH, 'w') as file: + file.write(customjs_content) + print(f"Modified nbextensions loader timeout limit to {limit} seconds") + + def main(): parser = argparse.ArgumentParser() parser.add_argument('--notebooks-dir', default='', type=str, help='The directory to start Jupyter from.') @@ -40,6 +66,7 @@ def main(): args = parser.parse_args() patch_cm_cypher_config() + patch_customjs() kernel_manager_option = "--NotebookApp.kernel_manager_class=notebook.services.kernels.kernelmanager.AsyncMappingKernelManager" notebooks_dir = '~/notebook/destination/dir' if args.notebooks_dir == '' else args.notebooks_dir From bca339a86a31e31ddab545347c6a74034f1b3d93 Mon Sep 17 00:00:00 2001 From: Michael Chin Date: Tue, 7 Mar 2023 20:19:18 -0800 Subject: [PATCH 2/3] Update changelog --- ChangeLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.md b/ChangeLog.md index 8a4288bb..c0374368 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -7,6 +7,7 @@ Starting with v1.31.6, this file will contain a record of major features and upd - Path: 04-Machine-Learning > Sample-Applications > 03-Real-Time-Fraud-Detection-Using-Inductive-Inference.ipynb - Added `--profile-misc-args` option to `%%gremlin` ([Link to PR](https://github.com/aws/graph-notebook/pull/443)) - Ensure default assignments for all Gremlin nodes when using grouping ([Link to PR](https://github.com/aws/graph-notebook/pull/448)) +- Fixed nbextensions loader timeout on large notebooks ([Link to PR](https://github.com/aws/graph-notebook/pull/455)) ## Release 3.7.1 (January 25, 2023) - Added ECR auto-publish workflow ([Link to PR](https://github.com/aws/graph-notebook/pull/405)) From 248896664cf7c5bc1c6dc77ed5078d2c4b1a4219 Mon Sep 17 00:00:00 2001 From: Michael Chin Date: Sun, 16 Apr 2023 19:27:09 -0700 Subject: [PATCH 3/3] update changelog --- ChangeLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.md b/ChangeLog.md index 0143ee52..d3c6302a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -5,6 +5,7 @@ Starting with v1.31.6, this file will contain a record of major features and upd ## Upcoming - Added support for Python 3.10 ([Link to PR](https://github.com/aws/graph-notebook/pull/476)) - Deprecated Python 3.7 support ([PR #1](https://github.com/aws/graph-notebook/pull/453)) ([PR #2](https://github.com/aws/graph-notebook/pull/473)) +- Patched nbextensions loader timeouts for large notebooks ([PR #1](https://github.com/aws/graph-notebook/pull/455)) - Fixed Dockerfile builds breaking with AL2023 ([Link to PR](https://github.com/aws/graph-notebook/pull/466)) - Fixed `--store-to` option for several magics ([Link to PR](https://github.com/aws/graph-notebook/pull/463)) - Fixed broken documentation links in Neptune ML notebooks ([PR #1](https://github.com/aws/graph-notebook/pull/467)) ([PR #2](https://github.com/aws/graph-notebook/pull/468))