Skip to content

Commit f8c9e6e

Browse files
Sergey TsimferSergey Tsimfer
authored andcommitted
Change order of communications in run
1 parent a3f398c commit f8c9e6e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

nbtools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
from .run_notebook import run_notebook
55
from .pylint_notebook import pylint_notebook
66

7-
__version__ = '0.9.10'
7+
__version__ = '0.9.11'

nbtools/run_notebook.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ def _wrapper(*args, **kwargs):
2323
returned_value = Queue()
2424
kwargs = {**kwargs, 'returned_value': returned_value}
2525

26+
json_path = None
27+
2628
try:
2729
process = Process(target=func, args=args, kwargs=kwargs)
2830
process.start()
2931

30-
path = kwargs.get('path', args[0])
32+
path = args[0] if args else kwargs['path']
3133
json_path = f'{TMP_DIR}/{process.pid}.json'
3234
with open(json_path, 'w', encoding='utf-8') as file:
3335
json.dump({'path': path}, file)
3436

37+
output = returned_value.get()
3538
process.join()
3639
except:
3740
# Terminate all relevant processes when something went wrong, e.g. Keyboard Interrupt
@@ -42,9 +45,10 @@ def _wrapper(*args, **kwargs):
4245
if psutil.pid_exists(process.pid):
4346
process.terminate()
4447
finally:
45-
os.remove(json_path)
48+
if json_path is not None and os.path.exists(json_path):
49+
os.remove(json_path)
4650

47-
return returned_value.get()
51+
return output
4852
return _wrapper
4953

5054
def get_run_notebook_name(pid):
@@ -369,6 +373,7 @@ def run_notebook(path, inputs=None, outputs=None, inputs_pos=1, replace_inputs_p
369373
exec_res['notebook'] = notebook
370374

371375
returned_value.put(exec_res) # return for parent process
376+
return
372377

373378
# Mask functions for database operations cells
374379
def mask_inputs_reading(notebook, pos):

0 commit comments

Comments
 (0)