1. The first method is to use the unhup command directly to let the program run in the background. The command format is as follows: unhup python filename.py (> ***.log )& In this command, python specifies that the file we want to execute is a python file, and the following file name .py is the file we want to execute. The content in brackets indicates that the content normally output to the console can be redirected to the *.log file. This is optional. If this is not done, the content will be output to the nohup.out file by default. The & after the brackets indicates background execution. 2. The second method is to write a script, submit the script to the server, and let the server run the statements in the script in the background. Suppose we define a script start.sh with the following content: #!/bin/bash cd the path name of the file you want to run python -u ***.py In the above script, #!/bin/bash means that this script uses /bin/bash to interpret and execute the following statements, where cd means jumping the current directory to the directory where the file to be run is located, and python -u ***.py means running the ***python file. After writing the script, we can use the following command to execute the script so that the program can run in the background: ./start.sh > result.log & Here, ./start.sh means running the script start.sh in the current directory, > result.log means outputting everything originally output to the console to the result.log file, and & means running in the background We can use the ps -e command to view the processes running in the background. In the above figure, we can see that our script start.sh and Python program have been successfully run in the background. Then we can view the information originally output to the console through cat result.log | more Note: To execute a function in a Python file, you must remember to call the function in the file in addition to defining the function. Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links You may also be interested in:
|
<<: How to modify the IP restriction conditions of MySQL account
>>: Comprehensive explanation of CocosCreator hot update
Origin: A few days ago, a tester sent a requireme...
Table of contents 1. Basic principles 2. Specific...
The drag function is mainly used to allow users t...
Table of contents 1. Reverse the numbers 2. Get t...
IIS7 needs to confirm whether the "URL REWRI...
Concept of SFTP sftp is the abbreviation of Secur...
Preface "High Performance MySQL" mentio...
This article shares the specific code of JavaScri...
Preface Review and summary of mobile terminal rem...
background A new server was added in the company,...
Introduction In the previous article, we installe...
Hyperf official website Hyperf official documenta...
Insert image tag <IMG> The colorful web page...
YSlow is a page scoring plug-in developed by Yaho...