forked from SMAT-Lab/SnifferDog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_jupyter.py
executable file
·30 lines (25 loc) · 1020 Bytes
/
run_jupyter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
import os
import sys
def run_single_notebook():
filename = sys.argv[1]
try:
with open(filename) as f:
nb = nbformat.read(f, as_version=4)
# filter out cells without execution count
cells = list(filter(lambda x:x['cell_type'] == 'code' and
x['execution_count'] is not None, nb.cells))
# if you wish to run the notebooks in the original execution counter order
# then sort code cells by oec values:
# cells.sort(key=lambda x:x['execution_count'])
nb.cells = cells # assign new cells
ep = ExecutePreprocessor(timeout=600)#timeout is set as 10 mins
res = ep.preprocess(nb, {'metadata': {'path': os.path.dirname(filename)}})
print('success')
except Exception as e:
print(e)
print('failed-filename:', filename)
return 0
if __name__ == '__main__':
run_single_notebook()