Running Python on SMP machine

Aahz Maruch aahz at panix.com
Mon Oct 9 12:48:16 EDT 2000


In article <8rrrg00nle at news2.newsguy.com>,
Alex Martelli <aleaxit at yahoo.com> wrote:
>"Aahz Maruch" <aahz at panix.com> wrote in message
>news:8rrks8$a1a$1 at panix3.panix.com...
>> In article <kubswv16xr.fsf at lasipalatsi.fi>,
>> Erno Kuusela  <erno-news at erno.iki.fi> wrote:
>>>>>>>> "William" == William Park <parkw at better.net> writes:
>>>
>>> | How do I take advantage of a SMP (2 CPU) machine?
>>>
>>>use separate processes.
>>
>> Why?  Why not use threads?
>
>Perhaps because of Python's single interpreter lock...?  If all
>your threads are running Python bytecode, I do not think you will
>ever be using the second CPU (haven't tried it, but this seems
>to be the effect of the current architecture as I understand it).

That's the Global Interpreter Lock.  But my experience is that
frequently the overhead of synchronizing between two separate processes
overwhelms the payback you get from actual use of SMP -- that trick works
best if the two processes do no synchronization.

Furthermore, it's not that hard to beat the GIL.  If any significant
amount of blocking I/O takes place, you'll benefit from threads.  In
addition, it's certainly possible to create C extensions for computation
that release the GIL.

Overall, it's almost always worth trying threading first.

[What I sometimes wonder is, how/why did *I* get to be the threading
champion on c.l.py?  It's not like I use threads very much, nor am I an
expert on them...  ;-)]
-- 
                      --- Aahz (Copyright 2000 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"[I have a] windmill fetish."  --Darkhawk



More information about the Python-list mailing list