[Tutor] Threading in Python
James
jtp at nc.rr.com
Thu Sep 20 04:56:19 CEST 2007
Thanks for the quick reply.
Interesting. I'm a little overwhelmed with the different terminology
(fork, spawn, thread, etc.). I'm under the impression that I'm
supposed to use os.fork() or os.spawn() for something like what I'm
trying to do (start multiple instances of the I/O utility from one
Python script).
However, from what I gather from the documentation, os.fork() is
going to fork the python Python script that calls the original fork
(so fork won't directly start off the programs that I need). How
would I go about forking + then executing an application? Isn't this
what spawn does? Or should I stick with fork + exec*?
Lots to learn, I guess. ;)
.james
On Sep 19, 2007, at 10:19 PM, Kent Johnson wrote:
> James wrote:
>> Hi. :)
>> I have a question regarding threading in Python. I'm trying to
>> write a wrapper script in Python that will spin off multiple
>> (lots!) of instances of an I/O benchmark/testing utility. I'm
>> very interested in doing this in Python, but am unsure if this is
>> a good idea. I thought I read somewhere online that because of
>> the way Python was written, even if I spun off (forked off?)
>> multiple instances of a program, all those child processes would
>> be restricted to one CPU. Is this true?
>
> Python *threads* are limited to a single CPU, or at least they will
> not run faster on multiple CPUs. I don't think there is any such
> restriction for forked processes.
>
>> I'm not sure if the utility I'm forking is CPU-intensive; it may
>> very well be. Does Python indeed have this limitation?
>
> I would think an I/O benchmark is more likely to be I/O bound...
>
>> Also, should I be using os.fork() for this kind of program?
>
> There is a fair amount of activity these days around making Python
> friendly to multi-processing. See
> http://wiki.python.org/moin/ParallelProcessing
>
> Kent
More information about the Tutor
mailing list