On Tue, Nov 15, 2011 at 12:56 PM, Blaine <frik...@gmail.com> wrote: > 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! > > Thanks! > Blaine > > _______________________________________________ > pypy-dev mailing list > pypy-dev@python.org > http://mail.python.org/mailman/listinfo/pypy-dev > > The canonical way is probably `import platform; platform.python_implementation()` which will return either "PyPy" or "CPython".
Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." -- Evelyn Beatrice Hall (summarizing Voltaire) "The people's good is the highest law." -- Cicero
_______________________________________________ pypy-dev mailing list pypy-dev@python.org http://mail.python.org/mailman/listinfo/pypy-dev