Greg Ewing, 09.03.2011 00:27:
Stefan Behnel wrote:

You *can* use Python references inside of nogil blocks, even if there's a
lot of stuff that you can't do with them, ... But you can access cdef
 > attributes on them,

Strictly speaking it's not even safe to do that, unless
you know there's some locking mechanism in effect that
prevents the underlying Python object going away from
under you.

Right. It also depends on where the reference came from. If it's held by a local variable that entered a nogil block, it's safe to use the reference, because it cannot be deallocated inside of the nogil block. However, if it is in a closure or in an object attribute that other parts of the code have access to, they may choose to change the binding, thus potentially deallocating the reference.

Maybe Cython could do another tiny bit more here, e.g. issue a minor warning for potential concurrency problems like this, that users could enable in their test suites.

Stefan
_______________________________________________
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel

Reply via email to