Variable ... is incomplete

277 views
Skip to first unread message

Toni Barth

unread,
Apr 6, 2015, 1:19:44 AM4/6/15
to cython...@googlegroups.com
Hi Folks,

probably this is a much to easy question but anyway, i'm facing it at
the moment.
Just the basics: I'll have to write a cython function which is called
asynchronously in another c thread and therefore has to hang into the
Python envrionment and so needs to call the PyGILState_Ensure() and
PyGILState_Release() things, so I did:

from cpython.pystate cimport *

cdef void myfunc():
cdef PyGILState_STATE gstate
gstate=PyGILState_Ensure()
...
PyGILState_Release(gstate)

The cythonization fails with the error message "Variable type
PyGILState_STATE is incomplete".

I'm using Cython 0.22.

What am I doing wrong?

Best Regards.

Toni

Stefan Behnel

unread,
Apr 6, 2015, 3:56:18 AM4/6/15
to cython...@googlegroups.com
Toni Barth schrieb am 06.04.2015 um 00:35:
> I'll have to write a cython function which is called
> asynchronously in another c thread and therefore has to hang into the
> Python envrionment and so needs to call the PyGILState_Ensure() and
> PyGILState_Release() things, so I did:
>
> from cpython.pystate cimport *
>
> cdef void myfunc():
> cdef PyGILState_STATE gstate
> gstate=PyGILState_Ensure()
> ...
> PyGILState_Release(gstate)
>
> The cythonization fails with the error message "Variable type
> PyGILState_STATE is incomplete".

Have you tried declaring your function as

cdef void myfunc() with gil:
... # do Python stuff here

and avoiding all that manual GIL handling? I keep forgetting if this also
works for plain C threads as in your case, but I think it should.

Stefan

Toni Barth

unread,
Apr 6, 2015, 5:08:32 AM4/6/15
to cython...@googlegroups.com
Hi,

thanks alot, I didn't know about that possibility, for now it works
fine, even if it raises a
Fatal Python error: PyEval_SaveThread: NULL tstate
, after running several times without problems. I'll see if it works all
fine after I wrote the whole function correctly and contact back if I
encounter this problem again. For now, do you have any clue what this
problem can result from?

Best Regards.

Toni

roman...@gmail.com

unread,
Jun 19, 2016, 11:59:01 AM6/19/16
to cython-users
Hi.
I  was stucked by the same problem as you mentioned in your post.
The cythonization fails with the error message "Variable type 
PyGILState_STATE is incomplete". My code is the same to yours.

Can you tell me  how you could figure it out ?
I tried all I can do ,but still can not solve this problem.

在 2015年4月6日星期一 UTC+8下午1:19:44,Toni Barth写道:
Reply all
Reply to author
Forward
0 new messages