[Tutor] Threading in Python
alan.gauld at btinternet.com
Thu Sep 20 09:45:16 CEST 2007
"James" <jtp at nc.rr.com> wrote
> I have a question regarding threading in Python. I'm trying to
> a wrapper script in Python that will spin off multiple (lots!) of
> instances of an I/O benchmark/testing utility.
Are these instances of an external program or simply instances
of some python code? If its an external program and you are on *nix
you may not need threading at all simply call os.system() with
the program in the background. Or if you need to communicate
with the program use threading and os.popen() (or the
subprocess module and its Popen class) to start the utility.
The utility as a separate process will be able to run on different
CPUs even though the threads all run in Python interpreter on
If OTOH the utility is python code then you will need to look at
using fork/exec or spawn.
I touch on os.fork in my inter-process comms topic of my tutor.
In your case instead of setting up a client/server you would
simply run your utility functions. But forking does give you
the potential to communicate results back to the parent
process via a pipe...
Author of the Learn to Program web site
More information about the Tutor