If you remotely execute programs via SSH or SSH-based tools (such as XShell, PyCharm, VSCode, etc., which can be used for debugging, but for long-term execution, please run commands as daemons), be sure to run your programs as daemons to avoid termination due to SSH connection interruptions, which could cause unnecessary losses.
screen, a tool for multiplexing terminal sessions.tmux, another commonly used tool (install with:apt-get update && apt-get install -y tmux).- JupyterLab Terminal.
- If you are using a Notebook, refer to the bottom of the JupyterLab documentation for issues related to log updates after network disconnections.
Jupyterlab
The simplest way is to run it through the JupyterLab terminal. As long as JupyterLab does not restart (which is very rare), the terminal will continue to run, regardless of whether the local host is disconnected from the network or shut down.
If the terminal displays nothing when opened, simply press the Enter key. When running code for an extended period in JupyterLab, it is highly recommended to redirect logs to prevent loss of intermediate logs in case of network disconnections. The method is as follows:
bash
screen
To installscreen, execute the following command in the terminal:
bash
Creating a New Session
Execute thescreen command in the terminal, and then press the Enter key in the resulting interface. You will see a terminal that appears identical to the previous one (in reality, there are now two).
Programs executed in this terminal are protected by this session. For example, you can run the following command here:
If you encounter chinese character encoding issues after opening a terminal with screen, execute the following command and then re-enter the screen terminal:
bash
Leaving a Session
When using the terminal opened with screen, pressing the shortcut keys Ctrl + a + d will detach you from the session and return you to the original terminal, displaying the message “detached.” This means that the session is simply disconnected, not terminated.Re-entering a Session
1
Step 1
Finding all detached sessions
screen -ls
This command will list all available screen sessions, including those that are currently detached. The output will look something like this:bash
2
Step 2
Reattaching to a Specific Session
screen -r <session_id>
For example, if the session ID is 12345, you would run:bash
3
Step 3
After executing the above commands, you will find that the ping www.huggingface.co command is still running. Therefore, you can run your program within a screen session, detach from the session, and then reattach to it when you need to check the logs.For example:
bash
Exiting a Session
In the terminal opened with screen, use the shortcut key Ctrl + d. If there is a running program, first terminate it with Ctrl + c.Character Encoding Issues
Add the-U parameter to resolve character encoding problems.
For example:
bash