[Python-Dev] threading (GilState) question

James Y Knight foom at fuhm.net
Sun Apr 10 22:54:08 CEST 2005


On Apr 10, 2005, at 11:22 AM, Michael Hudson wrote:

> Bob Ippolito <bob at redivi.com> writes:
>
>> Is there a good reason to *not* call PyEval_InitThreads when using a
>> threaded Python?
>
> Well, it depends how expensive ones OS's locking primitives are, I
> think.  There were some numbers posted to the twisted list recently
> that showed it didn't make a whole lot of difference on some platform
> or other... I don't have the knowledge or the courage to make that
> call.
>
>> Sounds like it would just be easier to implicitly call it during
>> Py_Initialize some day.
>
> That might indeed be simpler.

Here's the numbers. It looks like something changed between python 2.2 
and 2.3 that made calling PyEval_InitThreads a lot less expensive. So, 
it doesn't seem to make a whole lot of difference on recent versions of 
Python.

Three test programs:
${PYTHON} -c 'import pystone, time; print pystone.pystones(200000)'
${PYTHON} -c 'import thread, pystone, time; print 
pystone.pystones(200000)'
${PYTHON} -c 'import thread, pystone, time; 
thread.start_new_thread(lambda: time.sleep(10000), ()); print 
pystone.pystones(200000)'

All tests run using the same copy of pystone.

System 1: RH73, dual 3GHz Xeon
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-110)]
--------
Python 1.5.2 (#1, Apr  3 2002, 18:16:26)

(8.15, 24540)
(8.28, 24155)
(12.78, 15649)

Python 2.2.2 (#1, Jul 23 2003, 13:47:48)

(6.32, 31646)
(6.27, 31898)
(11.1, 18018)

Python 2.4.1 (#1, Apr  4 2005, 17:19:27)

(4.60, 43478)
(4.61, 43384)
(4.74, 42194)

System 2, FC3/64, dual 2.4GHz athlon 64.
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)]
--------
Python 2.3.4 (#1, Oct 26 2004, 16:45:38)

(3.84, 52083)
(3.80, 52632)
(3.98, 50251)

Python 2.4.1 (#1, Apr 10 2005, 15:47:53)

(3.09, 64725)
(3.08, 64935)
(3.26, 61350)

Python 2.4.1 (#1, Apr  1 2005, 16:45:07)
*compiled in 32 bit mode*

(3.35, 59701)
(3.42, 58480)
(3.57, 56022)



More information about the Python-Dev mailing list