-
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.
Test for parallel execution of notebooks
- Loading branch information
Showing
2 changed files
with
148 additions
and
5 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
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,84 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"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": [ | ||
"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)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.0" | ||
} | ||
}, | ||
"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