tags:

views:

56

answers:

3

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

A: 

There is a nice writeup of the various pieces/parts on how to do it at http://stackoverflow.com/questions/89228/how-to-call-external-command-in-python/92395 (per @lecodesportif).

The gist of a quick answer is:

retcode = subprocess.call(["ls", "-l"])
heckj
It fails the "without waiting" requirement.
Marius Gedminas
Ah - my bad, I missed that in the reading. You're quite correct. Stefano's answer should do what you want then.
heckj
A: 

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.

Marius Gedminas
+1  A: 

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.

stefano palazzo