executing multiple functions in background simultaneously

MRAB google at mrabarnett.plus.com
Tue Jan 13 20:35:01 EST 2009


James Mills wrote:
> On Wed, Jan 14, 2009 at 11:02 AM, Catherine Moroney 
> <Catherine.M.Moroney at jpl.nasa.gov> wrote:
>> I would like to spawn off multiple instances of a function and run
>> them simultaneously and then wait until they all complete. 
>> Currently I'm doing this by calling them as sub-processes 
>> executable from the command-line.  Is there a way of accomplishing 
>> the same thing without having to make command-line executables of
>> the function call?
> 
> Try using the python standard threading module.
> 
> Create multiple instances of Thread with target=your_function 
> Maintain a list of these new Thread instnaces Join (wait) on them.
> 
> pydoc threading.Thread
> 
The disadvantage of threads in Python (CPython, actually) is that
there's the GIL (Global Interpreter Lock), so you won't get any speed
advantage if the threads are mostly processor-bound.



More information about the Python-list mailing list