-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1017 from alexrudy/fix-history-multiprocessing
Disable IPython History in executing preprocessor
- Loading branch information
Showing
4 changed files
with
165 additions
and
5 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
28 changes: 28 additions & 0 deletions
28
nbconvert/preprocessors/tests/files/Check History in Memory.ipynb
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from IPython import get_ipython" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": { | ||
"scrolled": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"ip = get_ipython()\n", | ||
"assert ip.history_manager.hist_file == ':memory:'" | ||
] | ||
} | ||
], | ||
"metadata": {}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
65 changes: 65 additions & 0 deletions
65
nbconvert/preprocessors/tests/files/Parallel Execute.ipynb
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Ensure notebooks can execute in parallel\n", | ||
"\n", | ||
"This notebook uses a file system based \"lock\" to assert that two instances of the notebook kernel will run in parallel. Each instance writes to a file in a temporary directory, and then tries to read the other file from\n", | ||
"the temporary directory, so that running them in sequence will fail, but running them in parallel will succed.\n", | ||
"\n", | ||
"Two notebooks are launched, each with an injected cell which sets the `this_notebook` variable. One notebook is set to `this_notebook = 'A'` and the other `this_notebook = 'B'`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import os.path\n", | ||
"import tempfile\n", | ||
"import time" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# the variable this_notebook is injectected in a cell above by the test framework.\n", | ||
"other_notebook = {'A':'B', 'B':'A'}[this_notebook]\n", | ||
"directory = os.environ['NBEXECUTE_TEST_PARALLEL_TMPDIR']\n", | ||
"with open(os.path.join(directory, 'test_file_{}.txt'.format(this_notebook)), 'w') as f:\n", | ||
" f.write('Hello from {}'.format(this_notebook))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"start = time.time()\n", | ||
"timeout = 5\n", | ||
"end = start + timeout\n", | ||
"target_file = os.path.join(directory, 'test_file_{}.txt'.format(other_notebook))\n", | ||
"while time.time() < end:\n", | ||
" time.sleep(0.1)\n", | ||
" if os.path.exists(target_file):\n", | ||
" with open(target_file, 'r') as f:\n", | ||
" text = f.read()\n", | ||
" if text == 'Hello from {}'.format(other_notebook):\n", | ||
" break\n", | ||
"else:\n", | ||
" assert False, \"Timed out – didn't get a message from {}\".format(other_notebook)" | ||
] | ||
} | ||
], | ||
"metadata": {}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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