Multi-threading in Python vs Java

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Oct 11 05:30:48 EDT 2013


On Fri, 11 Oct 2013 17:53:02 +1100, Cameron Simpson wrote:

> Other Python implementations may be more aggressive. I'd suppose Jypthon
> could multithread like Java, but really I have no experience with them.

Neither Jython nor IronPython have a GIL.


> The standard answer with CPython is that if you want to use multiple
> cores to run Python code (versus using Python code to orchestrate native
> code) you should use the multiprocessing stuff to fork the interpreter,
> and then farm out jobs using queues.

Note that this really only applies to CPU-bound tasks. For tasks that 
depend on file IO (reading and writing files), CPython threads will 
operate in parallel as independently and (almost) as efficiently as those 
in other languages. That is to say, they will be constrained by the 
underlying operating system's ability to do file IO, not by the number of 
cores in your CPU.


-- 
Steven



More information about the Python-list mailing list