[Cython] porting mpi4py to PyPy runtime

Lisandro Dalcin dalcinl at gmail.com
Tue Nov 6 23:37:35 CET 2012


On 6 November 2012 16:22, Stefan Behnel <stefan_ml at behnel.de> wrote:
> Lisandro Dalcin, 02.10.2012 17:06:
>> After successfully porting mpi4py to PyPy 1.9, I want to share a few
>> issues I've encountered. The most serious onesare on PyPy's side, but
>> Cython do require a cuple of very minor fixes.
>> [...]
>> 4) mpi4py uses @classmethod decorator for many methods in cdef
>> classes. I really do not know what's going on, but method lookups do
>> not return the classmethod, but the original "unwrapped" method. I've
>> found a way to trick it, but again, I have no idea why it is working.
>> Basically, I have to execute hasattr() (in Python code, not Cython
>> code) on every class method: The hack reduces to adding the following
>> code at the very end of Cython code (note that I'm using "exec"):
>>
>> if PYPY: exec """
>> def _pypy_setup():
>>     for klass in (
>>         Status,
>>         Datatype,
>>         Request,
>>         Message,
>>         Op,
>>         Group,
>>         Info,
>>         Errhandler,
>>         Comm,
>>         Win,
>>         File,
>>         ):
>>         for name in klass.__dict__:
>>             meth = klass.__dict__[name]
>>             if (isinstance(meth, classmethod) or
>>                 isinstance(meth, staticmethod)):
>>                 hasattr(klass, name)
>> _pypy_setup()
>> del _pypy_setup
>> """
>>
>> I think (1) and (3) can be trivially handled in Cython, (3) is not an
>> issue for Cython as PyBuffer_FillInfo() is not directly used. And
>> about (4), we really need help from PyPy folks, they implement
>> PyType_Modified() as a non-op
>> (https://bitbucket.org/pypy/pypy/src/release-1.9/pypy/module/cpyext/typeobject.py#cl-726)
>> but that is not playing well with Cython.
>
> https://bugs.pypy.org/issue1106
>
> I had already opened a ticket for this one a while ago.
>

Can you test adding the following lines (add them after the Spam
class) to see if them "fix" the issue? Such hint could be useful for
PyPy folks:

exec """
for name in Spam.__dict__:
    hasattr(Spam, name)
"""



--
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169


More information about the cython-devel mailing list