My python script needs to start a background process and then continue processing to completion without waiting for a return.
The background script will process for some time and will not generate any screen output.
There is no inter-process data required.
I have tried using various methods subprocess, multiprocessing but am clearly missing something.
Does anyone have a simple example?
TIA
The easiest way of running a python script to run in the background is to use cronjob feature (in macOS and Linux). In windows, we can use Windows Task Scheduler. You can then give the path of your python script file to run at a specific time by giving the time particulars.
You can run multiple instances of a python script from a shell however from within a python program without the use of multithreading/multiprocessing the GIL limitation will impact what you are trying to do.
Role of nohup : nohup makes your script ignore SIGHUP , and redirects stdout/stderr to a file nohup. out, so that the command can continue running in the background after you log out. If you close the shell/terminal or log off, your command is no longer a child of that shell. It belongs to init process.
how about this:
import subprocess
from multiprocessing import Process
Process(target=subprocess.call, args=(('ls', '-l', ), )).start()
It's not all that elegant, but it fulfils all your requirements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With