Auto-save periodically during nbconvert

I’m currently executing a notebook with a command like jupyter-nbconvert --to notebook --execute work/notebook.ipynb

There is a cell in the notebook that takes about 16 hours to run.

Is there a command line option to save the notebook.nbconvert.ipynb periodically, like every 5 minutes? I want to be able to check the cell’s output while it’s running.

My understanding is that jupyter nbconvert doesn’t even save on a per cell basis, let alone as the cell progresses. See the last paragraph of my reply here where I suggest papermill if you want to look in as the run progress on a per cell basis. I don’t know how papermill handles outputting mid-cell execution.

There are some places where you have to do above and beyond the standard notebook cell model to accomplish what you need. Traditionally, jupyter notebooks aren’t ideal for long-running compute tasks (and there are efforts to address that such as this way to attach a sub-console to visualize intermediary results of a long-running computation); however, you are already partly addressing that shortcoming by executing the notebook on the command line. With some additional different approaches it usually can be adapted to still accomplish what you need. For example, it may be better to set up what is taking 16 hours to have logging steps where the progress you need to monitor is mirrored in an external log/text file (or other output forms) at times you control. You can also add in clean-up of that mirrored content at the end of the cell run so you aren’t necessarily permanently duplicating stdout or output. Or still using that approach of adding logging & mirroring, package things up into a script you can run separate from the notebook and then make output files that you then integrate into the notebook as documentation of that code run. Ideally, you can run that script behind a screen (or similar tech) and reattach to it and monitor it to your heart’s content using ps or other monitoring you’ve built in. Even if you don’t run the script separate packaging it up as a script you can run from inside the notebook with %run or %run -i, while adding the external logging or mirroring of output you want to monitor may suffice.

1 Like

thanks. this is almost what i ended up doing.

ipython work/notebook.ipynb

i’m already running it in a screen with -L so just changing from jupyter to ipython gives me the desired result

1 Like

This approach to answer 'Get partial output from nbconvert.preprocessors.ExecutePreprocessor seems related and so I’m noting here. It saves the notebook every second. I think the OP was seeking something much less often, and so it could be edited.

1 Like