New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access memoryview's size without GIL #2576

Open
jakirkham opened this Issue Aug 23, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@jakirkham
Contributor

jakirkham commented Aug 23, 2018

Appears that accessing the size attribute of a memoryview in a nogil section is invalid.

Code:

cimport numpy as np
import numpy as np

np.import_array()

cpdef void test(double[:, :] a) nogil:
    cdef size_t s = a.size

Error:

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

np.import_array()

cpdef void test(double[:, :] a) nogil:
    cdef size_t s = a.size
                    ^
------------------------------------------------------------

.ipython/cython/_cython_magic_6ed07c8c2df28ef0cf63065e4008e134.pyx:8:21: Coercion from Python not allowed without the GIL

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

np.import_array()

cpdef void test(double[:, :] a) nogil:
    cdef size_t s = a.size
                    ^
------------------------------------------------------------

.ipython/cython/_cython_magic_6ed07c8c2df28ef0cf63065e4008e134.pyx:8:21: Accessing Python attribute not allowed without gil

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

np.import_array()

cpdef void test(double[:, :] a) nogil:
    cdef size_t s = a.size
                   ^
------------------------------------------------------------

.ipython/cython/_cython_magic_6ed07c8c2df28ef0cf63065e4008e134.pyx:8:20: Converting to Python object not allowed without gil

Using Cython 0.28.5. on Python 3.6.6.

@scoder

This comment has been minimized.

Show comment
Hide comment
@scoder

scoder Aug 24, 2018

Contributor

view.size is calculated and actually implemented as a Python @property. It could certainly be precalculated, but I'm not sure it's worth it.

Contributor

scoder commented Aug 24, 2018

view.size is calculated and actually implemented as a Python @property. It could certainly be precalculated, but I'm not sure it's worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment