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
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.
Simple:
subprocess.Popen(["background-process", "arguments"])
If you want to check later whether the background process completed its job, retain a reference to the Popen object and use it's poll()
method.
There is a nice writeup of the various pieces/parts on how to do it at Calling an external command in Python (per @lecodesportif).
The gist of a quick answer is:
retcode = subprocess.call(["ls", "-l"])
精彩评论