cPython, IronPython, Jython, and PyPy (Oh my!)
Ethan Furman
ethan at stoneleaf.us
Wed May 16 18:45:20 EDT 2012
Ian Kelly wrote:
> On Wed, May 16, 2012 at 3:33 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
>> Just hit a snag:
>>
>> In cPython the deterministic garbage collection allows me a particular
>> optimization when retrieving records from a dbf file -- namely, by using
>> weakrefs I can tell if the record is still in memory and active, and if so
>> not hit the disk to get the data; with PyPy (and probably the others) this
>> doesn't work because the record may still be around even when it is no
>> longer active because it hasn't been garbage collected yet.
>>
>> For PyPy I can use `'PyPy' in sys.version` to set a constant
>> (REFRESH_FROM_DISK in this case) to disable the cPython optimization; does
>> anyone know what strings to look for for the other implementations?
>
> Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import sys
>>>> sys.subversion
> ('CPython', 'tags/r271', '86832')
>
> Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06)
> [Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_31
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import sys
>>>> sys.subversion
> ('Jython', 'tags/Release_2_5_2', '7206')
>
> I don't know what IronPython or PyPy return, but it should be
> something other than 'CPython'.
Thanks! That will do the trick. On CPython 2.4 .subversion does not
exist, so I'll use:
subversion = getattr(sys, 'subversion', None)
if subversion is not None and subversion[0] != 'CPython':
...
Hopefully all the others do have it defined (PyPy does, at least as of 1.8).
~Ethan~
More information about the Python-list
mailing list