thanks you guys for taking the time

Stefan Behnel schrieb:
> Christian Heimes wrote:
>   
>> Stefan Behnel wrote:
>>     
>>> BTW, are you sure that threading support has been initialised in your
>>> program? Just a wild guess, but maybe "import threading" at module level
>>> helps? If so, we may be able to fix that.
>>>       
>> I suspect the thread doesn't have a valid thread state. Python needs a
>> PyThreadState for every thread that runs Python code. You have to call
>> PyThreadState_New() inside the thread exactly once. The code in
>> Modules/threadmodule.c shows you how.
>>     
>
> Ah, yes, that's possible. So the idea would be to write a nogil function as
> callback, to do all the thread-state initialisation and cleanup manually in
> there, and then you can call into a with-gil function in between. Although
> that might look somewhat hackish all in all.
>   
According to [1] a new state can be declared by either do it manually by
calling PyThreadState_New() (and so on), by using some macros
(Py_BEGIN_ALLOW_THREADS, ...) of by calling PyGILState_Ensure (is this
what 'with gil' does?). But all of them do basically the same.
For now (not much testing has been done...) the problem seems to be
fixed by simply call PyEval_InitThreads() in my __init__ function, which
seems to be mandatory as soon as you use threads (Stefan is that what
you meant with "import threading", should this generally impose
something like this?)
As I really need these callbacks I'll see it this really works in the
future ;-)
> I don't think Cython can do much to improve this, as it cannot know the
> interpreter reference to use for tread-state creation. That has to be done
> in user code.
>   
If the problem lays in this missing call some documentation should be
added to the guide...

cheers
martin

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to