Question about Python threads
Stuart D. Gathman
stuart at bmsi.com
Wed Aug 21 21:05:32 EDT 2002
On Wed, 21 Aug 2002 14:18:38 -0400, Mr. Neutron wrote:
> If I understand, only one thread can be in the interpreter at any
> Now what I don't understand is being in the interpreter at a time part.
> Now the first thing that comes to mind is, that if only one thread can
> be in the interpreter at any time, the other CPU running a thread has to
> be blocked. Is my interpretation correct? It would seem that it would
> run very slowly, and not perform better than a single CPU system than.
That is correct. Current CPython code cannot use more than one CPU. A C
extension can release the GIL and get some parallelism (being careful to
reacquire the GIL before calling any Python API) - but that is probably
more trouble than its worth.
> How does this problem imply to Java as well?
Java threads are mapped to real OS threads (not necessarily one to one).
Java has no trouble taking advantage of multiple CPUs.
You might consider using Jython http://www.jython.org - which compiles
your python code to Java bytecode. Current implementations of Jython and
Java JVMs result in python programs that are slower than current CPython
on the same platform. However, that is still faster than most other
scripting languages, and your Python code would use as many CPUs as you
throw at it. (I would test it, though, since I haven't studied the
synchronization used by the Jython system. There might be a bottleneck
Stuart D. Gathman <stuart at bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.
More information about the Python-list