I have Jupyter running in a tmux session on an ec2 instance. I have very long-running cells, but when I close my browser or laptop lid, the notebook no longer writes output cells (and may crash the python kernel).
This is how I launch labs on my remote instance:
jupyter lab --ip=0.0.0.0 --port=5002 --no-browser --allow-root
I'm looking for a solution to run a notebook indefinitely without losing data and without having to keep my local computer on.
There has got to be a solution out there!
Update:
The 'nohup' solution below doesn't work:
After running this cell and closing the browser, upon reopening there is no output:
EDIT (after clarification):
You can use some Jupyter magic to continue running the cell after you close the browser or laptop, and then print the output after you return. Here's how that's done:
%%capture stored_output
import time
time.sleep(30)
print("Hi")
After returning, run the following:
stored_output.show()
# Hi
ORIGINAL:
You need to launch the notebook with nohup.
nohup jupyter notebook &
Adding the '&' is only needed to return the shell. The notebook will be running in the background and it's process ID won't be killed when you close your SSH connection.
I don't think what you want is possible because when your laptop goes into sleep mode after closing the lid, the notebook client in your browser will stop interacting with the server, even if you managed to keep the SSH connection alive. You could change your OS settings to prevent your system from sleeping upon lid closing, but that would be no different than keeping your machine on and using the battery.
The approach I use is:
stdout
or will be logged into a file in the server. When you awake your machine and restart the SSH connection, the cell will have finished running and you can inspect the results in another cell or look at your logs directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With