Skip to content
This repository has been archived by the owner on Jan 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #190 from jrleeman/multiprocessing
Browse files Browse the repository at this point in the history
Make notebook testing multithreaded
  • Loading branch information
jrleeman authored Apr 26, 2017
2 parents b9a1ae2 + 21190a0 commit e893536
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ install:
- source activate unidata-workshop
- python --version
- conda list
- python -m ipykernel install --user --name workshop

script:
- python run_notebooks.py
Expand Down
20 changes: 16 additions & 4 deletions run_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,41 @@
NOTEBOOKS_DIR = 'notebooks'
SKIP_NOTEBOOKS = [os.path.join('Bonus','What to do when things go wrong.ipynb'),
os.path.join('python-awips',
'NEXRAD3_Storm_Total_Accumulation.ipynb')]
'NEXRAD3_Storm_Total_Accumulation.ipynb'),
os.path.join('python-awips',
'Watch_and_Warning_Polygons.ipynb')]


def run_notebook(notebook):
args = ['jupyter', 'nbconvert', '--execute',
'--ExecutePreprocessor.timeout=900',
'--ExecutePreprocessor.kernel_name=workshop',
'--ExecutePreprocessor.kernel_name=python3',
'--to=notebook', '--stdout']

args.append(notebook)
with subprocess.Popen(args, stdout=subprocess.DEVNULL, stderr=None) as proc:
proc.wait()
return proc.returncode

results = []
def log_result(result):
results.append(result)

if __name__ == '__main__':
import glob
import multiprocessing as mp
import sys

ret = 0
notebooks = set(glob.glob(os.path.join(NOTEBOOKS_DIR, '**', '*.ipynb'), recursive=True))
notebooks -= set(os.path.join(NOTEBOOKS_DIR, s)
for s in SKIP_NOTEBOOKS)
for path in sorted(notebooks):
ret = max(run_notebook(path), ret)

with mp.Pool(processes=6) as pool:
for notebook in notebooks:
pool.apply_async(run_notebook, args=(notebook,), callback=log_result)
pool.close()
pool.join()

ret = max(results)
sys.exit(ret)

0 comments on commit e893536

Please sign in to comment.