How can I run a python script in ubuntu background? I tried to use '&', for example:
python3 test.py &
but when I close the terminal, this process seems to be closed as well because I can't get any update logs from this test script any more.
How can I run a python script in ubuntu background? I tried to use '&', for example:
python3 test.py &
but when I close the terminal, this process seems to be closed as well because I can't get any update logs from this test script any more.
You can use setsid. In your case by running:
setsid python test.py
Or, as mentioned in the comments, you can use nohup.
nohup python test.py
You can see the difference between them in this answer: What's the difference between nohup and a daemon?
I think you're looking for the nohup
command as Serge mentioned.
This answer looks like what you want