Vertex AI notebook kernel lost on PC sleep - google-cloud-platform

While using Vertex AI notebook instance kernel on GCP, the notebook gets detached everytime my system sleeps.
How can I keep my notebook running even if my system shuts down?

The Jupyter community has discussed this issue for quite a while now. There is no fix as such but there is a workaround to buffer the output and then display it when the notebook is opened again.
This answer is adopted from the comment from this Stack thread. I’ve also seen this workaround being suggested in a Jupyter Github issue.
The workaround would be to install the “Screen” utility (terminal multiplexer) on the GCE instance where JupyterHub is hosted, launch a new terminal session from JupyterHub and execute the notebook using the below “nbconvert” command.
jupyter nbconvert --to notebook --inplace --execute /home/path/to/notebook.ipynb
This way the terminal session could be preserved even if the personal computer is shut down and allow it to be resumed with the screen -r command.

Related

How to run Jupyter Lab on every startup on amazon ec2 instance?

I have already tried user-data method and rc.local methods but none are working. I am not a pro so would like some help on this.
These are the 3 commands i want to run on every startup of ec2 instance:
tmux (start a tmux session so i dont loose the data when connection resets)
source pyenv/bin/activate (Activate the venv)
jupyter-lab --ip 0.0.0.0 --no-browser --allow-root (run the jupyter lab)
I'm using a ubuntu ec2 instance btw. Thanks in advance.
If i can acheieve this using nohup instead of tmux i'd be willing to that as well.
I wasn't able to find a solution anywhere so any help is appreciated, thank you.

Google Cloud Shell Keep Disconnecting

looking for solution to prevent google cloud shell disconnecting when it found you idle, even it also disconnect when you run some processing and leave system idle.
message shown Connection to Cloud Shell has been lost. Any additional changes will not be saved.
This behavior is by design, as Cloud Shell is intended for interactive use only.
One way to fix it is running a ping command within a TMUX Terminal.
apt install tmux
apt update
tmux
ping google.com
Ctrl+b "
The downside of this is you'll be working halfscreen.

Restart Jupyter Lab server running in the background

I'm trying to restart a Jupyter Lab server (not just the kernels) running in the background of an AWS SageMaker notebook instance. I have already tried the following:
Killing the server by it's process ID
pgrep doesn't show me the process
pkill can't find the process
ps aux shows the process ID as constantly changing
Stopping the server through jupyter notebook stop
I get an SSL error and nothing happens
The only thing I've been able to do is reboot the entire instance, which isn't a great option as it can take awhile to become available again.
Edit 1:
The main reason I am trying to do this is that after installing the tqdm package and trying to use tqdm.notebook in Jupyter Lab, in order for it to display correctly I need to enable/install notebook and lab extensions. In order for these to take effect the server then needs to be restarted.
Try this:
Left hand navbar, Commands
Navigate to the Help section on the popout menu
Reset Application State
Both classic Jupyter and Jupyter lab live within the same process.
sudo initctl restart jupyter-server --no-wait is what AWS suggest in https://forums.aws.amazon.com/thread.jspa?messageID=917594&#917594
Assuming it runs on port 8888:
jupyter lab stop 8888 && jupyter lab

Setting up the VM server on Google Cloud to run Jupyter notebook

I am following tutorial how to run Jupyter notebook on Google Cloud Platform (https://towardsdatascience.com/running-jupyter-notebook-in-google-cloud-platform-in-15-min-61e16da34d52). I am stuck at "Step 8: Set up the VM server". I have created Jupyter configuration file by typing jupyter notebook
--generate-config
in SSH session. After checking if it was created with
ls ~/.jupyter/jupyter_notebook_config.py
I get message No such file or directory. I really don't understand what is going on. I have never created VM before and I am a biologist (who tries to become a data scientist, lost in IT terminology), all I want to do is merge my dataframes on the cloud as I am lacking memory in my laptop. Can you please help me?

Jupyter notebook kernel disconnecting / dead after sometime and cannot reconnect to amazon EC2 instance and complete ( currently running) operation.

When I connect to EC2 instance via Mobaxterm, after some period of time my jupyter notebook's kernel loses connection.
And some highly time-consuming operations /(Currently running tasks) are required to be re-performed again and again and are never-ending (This repeats each and every time).
I'm closing the notebook and restarting, so I can gain a connection to the kernel because it doesn't reconnect and I had to go through the process again and again when it dies eventually.
It also shows SSL error, wrong version number sometimes before disconnecting.
I have also faced a similar problem. I solved it with the help of 'tmux'.
I followed these steps:
I installed 'tmux' in my machine in the AWS instance.
[Actually, it came preinstalled with the AMI I had been using on the EC2 instance.]
I created a 'tmux' session simply by entering the command: tmux
Then I ran necessary commands to run the Jupyter server or Jupyter notebook
To close the terminal, I used this command: (i) ctrl + b, (ii) d
[Please notice, the session will continue running on the EC2 instance until you close the instance or close the jupyter server or the jupyter notebook].
To connect to the session again, I used the command: tmux attach
To finally kill the 'tmux' session when I am done, I used the command: tmux kill-session
Just use nohup. This should be the builtin tool in all Linux machines.
So you should do: nohup jupyter notebook > output.txt
And then you can safely terminate the console session without worrying about killing the notebook.