Skip to content

Instantly share code, notes, and snippets.

@subwaymatch
Created September 21, 2021 20:09
Show Gist options
  • Save subwaymatch/19b4521cc7501b6ade83e6da07a09fad to your computer and use it in GitHub Desktop.
Save subwaymatch/19b4521cc7501b6ade83e6da07a09fad to your computer and use it in GitHub Desktop.
Run Jupyter notebooks as a batch
import glob
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor, CellExecutionError
fpaths = glob.glob('pcard-submissions/*.ipynb')
for fpath in fpaths:
print(f'Running {fpath}')
nb = nbformat.read(fpath, as_version=4)
try:
print('=============================')
ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
ep.preprocess(nb)
except CellExecutionError as e:
print(f'CellExecutionError on {fpath}')
print('-----------------------------')
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment