Jupyter Cells Do Not Run Again

Ways to Get out the Jupyter Notebook Running and their drawbacks

Keeping the browser tab open to run Jupyter Notebook files for days is non the most heady piece of work. It can be troublesome. Here are some ways I found to solve the problems. Each solution has its benefits and drawbacks, so without further ado, let'due south start exploring each of them!

Photo by Andrew Neel on Unsplash

Utilize Google Colab

Colaboratory, or "Colab" for brusk, allows u.s. to run Python code with zero configuration and computation resource, like GPU / TPU, available. Using this, we tin can even run some bash commands by putting a prefix % before the CLI command. The benefit of this approach is that it is free and it allows importing files/dataset from Drive or Github. Information technology is well integrated with Google Bulldoze that nosotros can write code to automatically load some dataset from Drive and salve the network/effect to Bulldoze.

Notwithstanding, it has several drawbacks. First, it has limited computation usage. Once the limit is reached, it will stop running the code and shortly after, the files / variable values are lost. Yet, the limit is not that restricting. I found it to exist expert enough for training a Neural Network on some dataset, such every bit the Leaf Classification dataset. Moreover, information technology is possible to connect to a local runtime in instance yous demand bigger computation usage/resource.

Another drawback is that you can't close the browser tab for as well long, that is for more than xc minutes. In my experience, this can be prolonged by connecting to a local runtime.

Lastly, it may lose the log written when the tab is closed. This may exist an result when you need to keep all the log written in the Jupyter Notebook file. Some ways to handle this is to log the outputs into another file or use a specific logger.

Run it as a python script

In that location are means to run a Jupyter Notebook file as a python script.

1.Catechumen information technology into a python file

The simplest way is to open the Jupyter Notebook file in a browser, click File > Download equally > Python (.py). Later on that, nosotros can run the output file the way nosotros run a typical python file:

          python file_name.py        

All the same, log printed on the Jupyter Notebook files volition get lost.

ii.Run using command prompt directly

Another way is to run the jupyter notebook using CLI straight. It will allow us to continue all the logging printed in the jupyter notebook files throughout execution. There are two choices of programme to apply for this purpose, runipy or nbconvert. To install runipy or nbconvert, nosotros can employ pip/conda.

          # Using pip
pip install ipython
# Using conda
conda install ipython

If we employ runipy and have it installed, to run a jupyter notebook we tin can type:

          runipy MyNotebookFileName.ipynb        

To relieve the output of each cell dorsum to the notebook file, run:

          runipy MyNotebookFileName.ipynb        

If we use nbconvert and have it installed, to run a jupyter notebook we can type:

          jupyter nbconvert --to notebook --execute mynotebook.ipynb        

There are several other configuration options, such every bit timeout, report generation, and output files generation which can be found in these 2 sites, for runipy and nbconvert respectively.

To keep this command running in a remote server fifty-fifty when we disconnect from the remote server, we can configure screen or tmux and run the Jupyter'south command inside either i of them.

Still, i drawback I found from this approach is the lack of logging displayed to the user. Thus, even though the script will finish the execution in error, information technology may be difficult to track the progress of our code. When I used this approach, I utilize nvidia-smi and htop fustigate command to endeavor to guess the electric current state of the program.

Apply Remote Desktop to a server

This is by far my favorite approach. TLDR, it handles all the disadvantages of the previous methods. It allows me to see the progress of the lawmaking too equally the output of each cell. The script stays running even when I'm disconnected.

ane.Configure a remote desktop on the server

You may skip this step if the server has had a remote desktop configured. This step is probably the trickiest step of all, especially when the server's Os version is outdated.

a. Connect to the server through SSH

b. Install some packages

          sudo apt update
sudo apt install -y ubuntu-desktop xrdp

PS: If you don't have a sudo permission in the server, alternatively, yous may install the parcel from Github using wget and build it from source. You may too need to exercise so to downgrade the version of xrdp if the xrdp version downloaded has some bugs or incompatibility with the OS.

c. Edit the RDP configuration file, /etc/xrdp/xrdp.ini, on the server. A minimal configuration might wait like this:

          [globals]
bitmap_cache=yes
bitmap_compression=yes
port=3389
crypt_level=low
channel_code=one
max_bpp=24

[xrdp1]
name=sesman-Xvnc
lib=libvnc.so
username=ask
password=ask
ip=127.0.0.1
port=ask-one

Annotation the port written, information technology is important for making connection. Besides, if your server is an EC2 instance, we need to edit the security group appropriately to allow inbound TCP connection in port 3389 .

d. Restart the xrdp

          sudo service xrdp restart        

e. Install Window Manager for RDP connection. This involves changing the contents of a user's .xsession file.

          sudo apt install -y xfce4 xfce4-goodies
echo xfce4-session >~/.xsession

You're ready to connect! 💃🏽💃🏽

2.Setup Remote Desktop Customer in your reckoner

This step will let your computer to connect to the server. The way to practise it varies based on the OS of your computer.

For Linux, install vinagre and open up it. Enter the IP address for the server, username and the RDP port. And so, click Connect.

For Windows or others, the above step can be done using Remote Desktop Viewer.

Remote Desktop Viewer on my Kali Linux computer

For Mac, I use the Microsoft Remote Desktop. Make full the form appropriately and click Add together.

Microsoft Remote Desktop in Mac.

Afterward that, you lot will be prompted to enter your credentials. Leave port equally information technology is.

xrdp login form

Once yous're authenticated you lot should see your desktop.

Remote Desktop!

iii.Run the jupyter notebook in the browser of the server

This can be done by typing jupyter notebook in the last, which will open up a browser. Then, navigate to the respective jupyter notebook file in the browser and open it.

Click Prison cell > Run All on the toolbar.

Then close the Remote Desktop Client awarding. Call back not to close the browser instead! 😉😉

All done! Now you can go out the browser running in the remote desktop and disconnect to information technology someday you want to. You can likewise bank check back the progress of the program by reconnecting.

kauffmannhistras.blogspot.com

Source: https://towardsdatascience.com/keep-jupyter-notebook-running-even-after-browser-is-closed-9a1937b7c615

Related Posts

0 Response to "Jupyter Cells Do Not Run Again"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel