Martin Gysel wrote:
> 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 ;-)

You are confusing the API functions. Py_BEGIN_ALLOW_THREADS doesn't
creating a new thread state. Only PyThreadState_New() creates a new
thread state.

PyGILState_Ensure() and PyGILState_Release() are convenient wrappers
that create and destroy thread states for a thread. It's important to
know that they don't work with subinterpreters as used by mod_python and
mod_wsgi. The release() method also destroys the thread state object
when the internal counter reaches zero. That may be a speed issue when a
short running callback is called often.

Christian

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

Reply via email to