Closed IPython Notebook that was running code

Viewed 5667

How it works? I got some code running in an IPython Notebook. Some iterative work.

Accidentally I closed the browser with the running Notebook, but going back to the IPython Dashboard I see that this particular Notebook hasn't Shutdown, so if I open the Notebook again I see the [*] in front of my code that it was executing.

I even can hear my PC still running the code, but it doesn't return me any new output of the print statements.

Can I wait and eventually continue with the output, or my PC will still running my code, but it won't be accessible anymore?

3 Answers

use this code to save the output to file

import time
from threading import Thread
import sys
#write the stdout to file
def log():
    #for stop the thread
    global run
    while (run):
        try:
            global out
            text = str(sys.stdout.getvalue())
            with open("out.txt", 'w') as f:
                f.write(text)
        finally:
            time.sleep(1)
%%capture out
run = True
print("start")
process = Thread(target=log, args=[]).start()

# do some work
for i in range(10, 1000):
    print(i)
    time.sleep(1)
run= False
process.join()

It is useful to use a text editor that tracer changes the file and suggest reloading the file like notepad++

Related