我在python中传递一个函数指针给C编写的dll, 在dll中保存回调函数指针,并且开启一个线程,间隔调用此回调函数,函数可以正常运行(函数里面就一条打印语句),但是没有进入python定义的函数体执行,而回调函数可以正常执行,看起来应该是重新开辟了一块内存,将python的这个回调函数进拷贝过去了。这是咋回事,如何解决?
可以直接传递数据,而不是函数指针,你不同语言处理起来没那么方便
---------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!
官网资料明确指出我的这种用法行不通:
Also, note that if the callback function is called in a thread created outside of Python’s control (e.g. by the foreign code that calls the callback), ctypes creates a new dummy Python thread on every invocation. This behavior is correct for most purposes, but it means that values stored with threading.local will not survive across different callbacks, even when those calls are made from the same C thread.