For what I am doing I use the multiprocessing module that arms talks about.
If you peek inside the code it just basically wraps the "fork" function.
As perks said. Amazingly enuff with increased forks your memory ussuage hardly goes up.
Ur processor ussuage will but not ur memory.
multiprocessing module is good if u are running same group of python "functions" etc.
There are a few crevates. Also if there is possibily that one of the subprocess with seg fault do not use shared memory.
If u want to do run "non-python" programs.
Then use subprocess
Advantage is u automatically have the stdin/stdout/stderr pipes attached
def runGocr(pilImage):
io = StringIO.StringIO()
pilImage.save(io,"ppm")
imgStr = io.getvalue()
io.close()
p = subprocess.Popen(("gocr", "-"),
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
close_fds = True)
stdout_text, stderr_text = p.communicate(imgStr)
return stdout_text.strip()
notice in the above snippit how the image is directly piped into GOCR using stdin.
Notice how the result is pulled out from stdout
In the above case it will block (which is what i want it to do) but you can check out module.