E
E
Evgeny_A2019-10-08 14:08:57
Layout
Evgeny_A, 2019-10-08 14:08:57

How to correctly run a Python script in the background via SSH?

Hello.
I can't figure out why all of the following options for running a Python script in the background don't work as I expect. I have a script that uses the multiprocessing library to parse a site. The script should run for 7-9 days. I check if the script is running in the background or not using the ps command.
Here's what I've tried:
nohup python3 script.py
After entering a command, the terminal displays the message "nohup: ignoring input and appending output to 'nohup.out'", but does not allow a new command to be entered while in command processing mode. If you press ctrl + c, then control over the console is returned, but the script stops working. If the console is closed, the process started by the script dies.
python3 script.py > /dev/null&
In this case, the console returns the number of the running process, but instead of the expected silence from the script, I see various script service messages in the console (mostly warnings from the urllib3 library). The console, as in the first case, does not allow you to enter new commands without entering ctrl + c. If you close the console, the script is disabled.
python3 script.py > script.log 2>&1 /null &
The console returns the running process number, no warnings are printed. If you close the console and then start it again, then after entering the ps command, the process exists, but randomly the process dies. Sometimes after 5 minutes, sometimes after 5 hours. There are no crash messages in the log file (script.log) at all.
Tell me how to run the script so that it works correctly in the background or how to debug the current situation?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sergey, 2018-07-01
@zorro76

use ion.RangeSlider for these purposes,
you can see the implementation on my project: project in the selection of goods, click on Price

L
lz961, 2019-10-08
@Evgeny_A

nohup python3 script.py &
ps -e | grep python

P
Prog, 2019-10-08
@damprog

use screen

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question