[Cython] nogil doesn't seem to work when defined on extern cpp functions

Ryan Pessa ryan at essential-elements.net
Wed May 8 20:09:14 CEST 2013


Hello,

I ran into an interesting problem today. It doesn't seem like Cython
respects the `nogil` statement on extern cpp functions. I am trying to use
a blocking I/O function, and am running it in secondary thread so I can use
another library function to cancel it.

I have tried it both on the `extern` line:
    cdef extern from "digitalpersona/dpfp_api.h" nogil:
        uint32_t DPFPGetEvent(dp_uid_t* pDevUID, dp_device_event_t**
ppEvent, uint32_t uTimeoutMsec)
and on the function itself:
    cdef extern from "digitalpersona/dpfp_api.h" nogil:
        uint32_t DPFPGetEvent(dp_uid_t* pDevUID, dp_device_event_t**
ppEvent, uint32_t uTimeoutMsec) nogil

Either way, this statement still blocks other threads:
    res = dpfp_api.DPFPGetEvent(pIdDev, &pEvent,
dpfp_api.DP_TIMEOUT_INFINITE)
While this statement does not:
    with nogil:
        res = dpfp_api.DPFPGetEvent(pIdDev, &pEvent,
dpfp_api.DP_TIMEOUT_INFINITE)
All variables used (res, pIdDev, pEvent) are C variables.

Obviously this is not a huge issue, as I can bypass the GIL using `with
nogil`. But I figured it would be a good idea to report it anyway.

Ryan Pessa
AerisPOS Project Manager / Developer
Essential Elements <http://www.essential-elements.net/> |
AerisPOS<http://www.aerispos.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20130508/4b5b6cb5/attachment.html>


More information about the cython-devel mailing list