[capi-sig] Threading failure
stefan_ml at behnel.de
Mon Jul 19 07:10:33 CEST 2010
Mark Hammond, 19.07.2010 03:15:
> On 6/07/2010 4:36 AM, Paul Grunau wrote:
>> I asked this question here a few days ago, and someone suggested I ask
>> providing all the code, so that it can be actually tried. So here it
>> is, and I’m still stumped.
> It isn't clear that this is your problem, but all your methods which
> return None fail to increment it's reference count.
Good call. Since returning None is so common, there's even a macro for
that, called Py_RETURN_NONE.
A suggestion to the OP at this point: using Cython instead of C makes it
easy to get the ref-counting right, as you don't have to care about it there.
Another very common thing to get wrong: if the callback comes within a
completely new thread that was not created by Python, you need to set up
Python's thread state first. PyGILState_Ensure() is not enough in this
case. See the C-API docs.
More information about the capi-sig