1

If I run

import time
for i in range(999):
    print (i)
    time.sleep(1)

close the tab and reopen, it wont show the live output stream. I checked, its running in the background.

is there a way to come back to a running script after I closed the tab?

video demo: https://i.stack.imgur.com/5sioA.jpg

Arye P.
  • 163
  • 4
  • 11

1 Answers1

2

First thing first: code doesn't stop on tab closing (and you can see it from the log if you are launching JN from Anaconda Prompt). This is a good hint to find a viable solution.

Actually there are many ways to do this, and I'll suggest to dig this very good answer for a lot of other methods.

To me the most Jupyter Notebook-ish solution is to use the cell magic %%capture.

How to use it:

%%capture temp_output
# your running script here

Save the Notebook, close the tab, do whatever you want. Go back to the notebook, open it and:

temp_output.show()

Will let have your result.

Carlo
  • 444
  • 4
  • 12