python threads on multi-CPU machines
Duncan Booth
duncan at NOSPAMrcp.co.uk
Mon Aug 18 04:34:31 EDT 2003
Thomas Womack <twomack at chiark.greenend.org.uk> wrote in
news:vQn*aWb0p at news.chiark.greenend.org.uk:
> If I have a dual-processor hyperthreaded machine (so with four CPU
> contexts), will a python program distribute threads over all four
> logical processors?
>
> I ask because I'm fairly sure that this *does* happen using the
> threading extensions in MFC, and fairly sure that it *doesn't* when
> using Java, so I don't see that the result is obvious for python.
The C implementation of Python uses a global interpreter lock that only
allows one thread to interpret bytecode at a time, so while the threads may
be distributed across multiple processors you will get little or no speedup
over a single processor. (If your threads spend most of their time in a
non-Python extension, they may be able to get some benefit from multiple
processors).
The only way to take advantage of multiple processors with Python is to run
at least one separate process for each processor. For example, I believe
Zope will take advantage of multiple processor systems if you run it in ZEO
client/server mode with several Zope client processes.
I believe that Jython simply does whatever the Java implementation does.
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list