Skip to content

Commit

Permalink
Change order of communications in run
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Tsimfer authored and Sergey Tsimfer committed Aug 14, 2023
1 parent a3f398c commit f8c9e6e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nbtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from .run_notebook import run_notebook
from .pylint_notebook import pylint_notebook

__version__ = '0.9.10'
__version__ = '0.9.11'
11 changes: 8 additions & 3 deletions nbtools/run_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ def _wrapper(*args, **kwargs):
returned_value = Queue()
kwargs = {**kwargs, 'returned_value': returned_value}

json_path = None

try:
process = Process(target=func, args=args, kwargs=kwargs)
process.start()

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

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

return returned_value.get()
return output
return _wrapper

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

returned_value.put(exec_res) # return for parent process
return

# Mask functions for database operations cells
def mask_inputs_reading(notebook, pos):
Expand Down

0 comments on commit f8c9e6e

Please sign in to comment.