Skip to content

Commit ce11074

Browse files
authored
Fix nbextensions loader timeout on large notebooks (#455)
* Fix nbextensions loader timeout on large notebooks * Update changelog * update changelog --------- Co-authored-by: Michael Chin <chnmch@amazon.com>
1 parent 2c7e99f commit ce11074

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Starting with v1.31.6, this file will contain a record of major features and upd
55
## Upcoming
66
- Added support for Python 3.10 ([Link to PR](https://github.com/aws/graph-notebook/pull/476))
77
- 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))
8+
- Patched nbextensions loader timeouts for large notebooks ([PR #1](https://github.com/aws/graph-notebook/pull/455))
89
- Fixed Dockerfile builds breaking with AL2023 ([Link to PR](https://github.com/aws/graph-notebook/pull/466))
910
- Fixed `--store-to` option for several magics ([Link to PR](https://github.com/aws/graph-notebook/pull/463))
1011
- 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))
@@ -24,6 +25,7 @@ Starting with v1.31.6, this file will contain a record of major features and upd
2425
- Added `--profile-misc-args` option to `%%gremlin` ([Link to PR](https://github.com/aws/graph-notebook/pull/443))
2526
- Added error messaging for incompatible host-specific `%%graph_notebok_config` parameters ([Link to PR](https://github.com/aws/graph-notebook/pull/456))
2627
- Ensure default assignments for all Gremlin nodes when using grouping ([Link to PR](https://github.com/aws/graph-notebook/pull/448))
28+
- Fixed nbextensions loader timeout on large notebooks ([Link to PR](https://github.com/aws/graph-notebook/pull/455))
2729

2830
## Release 3.7.1 (January 25, 2023)
2931
- Added ECR auto-publish workflow ([Link to PR](https://github.com/aws/graph-notebook/pull/405))

src/graph_notebook/start_notebook.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
HOME_PATH = os.path.expanduser("~")
1111
NBCONFIG_DIR_TREE = HOME_PATH + '/.jupyter/nbconfig'
12-
CFG_FILE_NAME = 'notebook.json'
13-
NOTEBOOK_CFG_PATH = NBCONFIG_DIR_TREE + '/' + CFG_FILE_NAME
12+
NOTEBOOK_CFG_PATH = NBCONFIG_DIR_TREE + '/notebook.json'
13+
14+
CUSTOM_DIR_TREE = HOME_PATH + '/.jupyter/custom'
15+
NOTEBOOK_CUSTOMJS_PATH = CUSTOM_DIR_TREE + '/custom.js'
1416

1517

1618
def patch_cm_cypher_config():
@@ -33,13 +35,38 @@ def patch_cm_cypher_config():
3335
json.dump(notebook_cfg, file, indent=2)
3436

3537

38+
def patch_customjs():
39+
# Increases time allotted to load nbextensions on large notebooks. Limit is set to 60s and can be increased further.
40+
# Reference: https://github.com/ipython-contrib/jupyter_contrib_nbextensions/blob/master/docs/source/troubleshooting.md#extensions-not-loading-for-large-notebooks
41+
limit = "60"
42+
increase_requirejs_timeout_prefix = "window.requirejs.config({waitSeconds:"
43+
increase_requirejs_timeout_suffix = "});"
44+
requirejs_timeout_full = increase_requirejs_timeout_prefix + limit + increase_requirejs_timeout_suffix
45+
46+
try:
47+
os.makedirs(CUSTOM_DIR_TREE, exist_ok=True)
48+
with open(NOTEBOOK_CUSTOMJS_PATH, 'r') as file:
49+
customjs_content = file.read()
50+
except (json.decoder.JSONDecodeError, FileNotFoundError) as e:
51+
customjs_content = ""
52+
53+
if increase_requirejs_timeout_prefix not in customjs_content:
54+
if customjs_content:
55+
customjs_content += "\n"
56+
customjs_content += requirejs_timeout_full
57+
with open(NOTEBOOK_CUSTOMJS_PATH, 'w') as file:
58+
file.write(customjs_content)
59+
print(f"Modified nbextensions loader timeout limit to {limit} seconds")
60+
61+
3662
def main():
3763
parser = argparse.ArgumentParser()
3864
parser.add_argument('--notebooks-dir', default='', type=str, help='The directory to start Jupyter from.')
3965

4066
args = parser.parse_args()
4167

4268
patch_cm_cypher_config()
69+
patch_customjs()
4370

4471
kernel_manager_option = "--NotebookApp.kernel_manager_class=notebook.services.kernels.kernelmanager.AsyncMappingKernelManager"
4572
notebooks_dir = '~/notebook/destination/dir' if args.notebooks_dir == '' else args.notebooks_dir

0 commit comments

Comments
 (0)