python basic programming: Several methods Linux Python programs running in the background to explain

Today small share an article on Linux are several ways to explain the background to run Python programs, small series that the content very good, for everyone to share and now has a good reference value, a friend in need for everyone to follow the small series with a look Look
1. the first method is the direct use of unhup command to let the program run in the background, the command format is as follows:

unhup python 文件名.py (> ***.log )&

In this command, specify the file we want to execute python for python files behind the file name .py file that is we want to execute. Brackets indicate the content can be output to the content usually redirected to console * .log this document, this is optional, if not this, the output file will default to nohup.out. Brackets indicate your back & running in the background.

2. The second method is to write a script, and then submit scripts to the server, the server to run in the background script statements inside. Suppose we define a script start.sh, which reads as follows:

#!/bin/bash
cd 想要运行文件的路径名
python -u ***.py

The above script, #! / Bin / bash refers to this script using / bin / bash to explain execute the following statement, which is the current directory cd jump to the directory where the file you want to run, then python -u ***. Py it is running *** python file, when finished the script, we can use the following this command to execute the script so that programs running in the background:

./start.sh > result.log &

Here ./start.sh represent start.sh script running under the current directory,> result.log represents the original output to the console output to everything result.log file, & means run in the background

We can run a background check through the ps -e command process What are Here Insert Picture Description
the chart we can see, our script start.sh and Python programs have been successfully running in the background, and then through the cat result.log | more since you can see the original output to the console
write to you, for everyone to recommend a very wide python learning resource gathering, click to enter , there is a senior programmer before learning to share experiences, study notes, there is a chance of business experience, and to we curated a python to combat zero-based information projects, python day to you on the latest technology, prospects, learning small details that need to comment
Note: to perform a function python file, we must remember that in addition to the definitions outside the function, but also call the function in the file

to sum up

That's all for this article, I hope the contents of this paper has some reference value of learning for everyone to learn or work

Published 15 original articles · won praise 2 · views 10000 +

Guess you like

Origin blog.csdn.net/haoxun11/article/details/104908105