I have C++ dll which works with multiple threads. So I wrapped this library with Cython and created special receiver callback-function, which must adds some results to asyncio.Queue.
cdef void __cdecl NewMessage(char* message) nogil:
I marked it as nogil, this callback calls from another thread. In this callback I just use:
with gil:
print("hello") # instead adding to Queue. print("hello") is more simple operation to demostrate problem
And got deadlock here. How to resolve it?
C++ callback declaration (header):
typedef void (*receiver_t)(char*);
void SetReceiver(receiver_t new_rec);
cpp:
static receiver_t receiver = nullptr;
void SetReceiver(receiver_t new_rec)
{
printf("setted%i\n", (int)new_rec);
a = 123;
if (new_rec != nullptr)
receiver = new_rec;
}
Cython code:
cdef extern from "TeamSpeak3.h":
ctypedef void (*receiver_t) (char*) nogil
cdef void __cdecl SetReceiver(receiver_t new_rec) nogil
cdef void __cdecl NewMessage(char* message) nogil:
with gil:
print("hello")
SetReceiver(NewMessage)
Full code: .h http://pastebin.com/ZTCjc6NA
.cpp http://pastebin.com/MeygA8im