[pypy-dev] Detecting pypy vs cpython runtime

Blaine frikker at gmail.com
Tue Nov 15 18:56:47 CET 2011

Hi everyone. I have a cellular automata framework in C++ and I use cython
and cpython to run it. I found out that if I port it to pure python and run
it with pypy, it's close to the same performance as the C++ version. (about
2x as slow, compared to 20x as slow when using pure python + cpython). When
I throw in other overheads with pure python libraries, using the pure
python and pypy is much faster than cpython with the C++ library, all
things equal.

What I'd like to do is detect if pypy or cpython is doing the importing of
my module, and switch over to the pure python interface if pypy is found.
As it stands I have to do it manually in my module's __init__.py.

*Is there any way to detect if my module is being imported by pypy vs
cpython?* Either via sys, or maybe some latent variable that is present, or
something else. sys.argv[0] only has the script name (obviously), not the
interpreter call.

Keep up the outstanding work. Pypy is great!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20111115/0a67ad4c/attachment.html>

More information about the pypy-dev mailing list