Corresponding to deep learning , At present, we are all writing code locally , And then through ide( Such as pycharm) Connect to server , Transmit code and data , And then in ide Run code in , You can run the program on the server .pycharm Please see this blog post to connect to the server pycharm Connect to server
If that's all there is to it , Then the local computer has been shut down , The program running on the server is closed .
So how to turn off your local computer , At the same time, the server can continue to run programs ? Please see below .
Local IDE yes :PyCharm
Server is Linux System
Step1: Check for installation screen
Use command :
screen -ls
Check for screen, If the report is wrong , No installation screen.
Step2: Connect to the remote server , Install with command screen
CentOS Series systems : yum install screen
Ubuntu Series systems : sudo apt-get install screen
Step0: Test code introduction
import time
import datetime
import os
time.sleep(20)
data_path = "../data/"
# 1. Create a file object
file_name = os.path.join(data_path, 'test_screen.txt')
file = open(file_name, mode='w')
file.writelines(str(datetime.datetime.now()))
file.close()
for i in range(30):
time.sleep(5)
print("the number is = ", i)
(1) extend 20 Seconds later , Write the current time to txt In file .( It is convenient to observe offline , Successful operation )
(2) Every delay 5 second , Output a paragraph of text .( It is convenient to re-enter the program , Observe whether the program is still running )
Step1: Connect to remote server
No matter use pycharm still Xterm Or other software , Connect to the remote server .
Next steps , We can learn from : Use screen Implement the server to run the project alone
Step2: Create a screen
(base) [email protected]:~# screen -S test
Step3: Check out the screen
(base) [email protected]:~# screen -ls
There are screens on:
14154.test (03/29/2020 11:01:58 AM) (Attached)
1 Sockets in /run/screen/S-git.
Step4: Switch the path to the location of the file
(base) [email protected]:~# cd /home/folders/Fiona/program
Step5: Activate your environment
(base) [email protected]:/home/folders/Fiona/program# conda activate Fiona0329
Step6: Run code
(Fiona0329) [email protected]:/home/folders/Fiona/program# python run.py
Step7: Press ctrl+a+d, sign out screen. Then you can turn off your local computer , The server will now run the program itself
I'll just put pycharm Shut down the . After operation , Re enter the previously created screen, Check the results of the program .
Step8: Reopen screen
(1) First use the command to find the previously created screen:
(2) Reopen screen
(base) [email protected]# screen -r 15659.test
At this point, you can view the results of the previously run code , As shown in the figure :
The application will now run its own program **
Result display
After completing the above steps , I just shut it down pycharm. After a while , I then entered the creation of screen, Found that the program has finished running , The content is also written successfully , The output is also correct . See the picture for details :
The results are very satisfactory , After I shut down my local computer , The server can still run programs on its own , And output the result . After re entering the operation interface , You can also see the output of the program , perfect !
Step9: Delete screen
Find the to delete before deleting screen:
And then delete it :
(base) [email protected]# screen -X -S 16283.you quit
After deleting , Check it again , There are no deleted screen 了 :
The end , And the flower !!