在python绑定中可能出现分段错误的原因是什么?

我想用cython编写python绑定到ac库。 该库表示一个多线程的http服务器,并通过头文件公开它的API。 遵循cython指南,我写了一个pxd和pyc文件,其中包含3个基本函数的定义:

struct server *server_init()
int server_start(struct server *)
int server_stop(struct server *)

python包装看起来类似于:

cdef class Server:
    cdef library.server *_server

    def __cinit__(self):
        self._server = library.server_init()

    def server_start(self):
        return library.server_start(self._server)

    def server_stop(self):
        return library.server_stop(self._server)

绑定工作正常,服务器启动并提供内容,但是,当我从python停止服务器时,大部分时间,python解释器崩溃并出现分段错误。 崩溃发生在从c server_stop返回后,我不知道是什么会导致段错误。

内存分配/初始化/免费发生在这3个函数中,并且完全由c库在内部处理。

也许我错过了一些东西,那么可能是分段错误错误的原因是什么?

编辑:

它不会在valgrind和gdb中重现。 但是,我生成了一个核心转储,并且回溯如下所示:

#0  0x00007f4cd0020008 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#1  0x00007f4cd00208b3 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#2  0x00007f4cd0020c54 in _Unwind_ForcedUnwind () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#3  0x00007f4cd5194630 in __GI___pthread_unwind (buf=<optimized out>) at unwind.c:129
#4  0x00007f4cd518c85b in __do_cancel () at ../nptl/pthreadP.h:264
#5  sigcancel_handler (sig=<optimized out>, si=<optimized out>, ctx=<optimized out>) at nptl-init.c:214
#6  sigcancel_handler (sig=<optimized out>, si=<optimized out>, ctx=<optimized out>) at nptl-init.c:173
#7  <signal handler called>
#8  0x00007f4cd4eba72b in accept4 (fd=<optimized out>, addr=..., addr_len=<optimized out>, flags=<optimized out>) at ../sysdeps/unix/sysv/linux/accept4.c:38
#9  0x00007f4cd3a2ee50 in ?? ()
#10 0x0000000000000000 in ?? ()
链接地址: http://www.djcxy.com/p/43897.html

上一篇: What could be the reason for segmentation fault in python bindings

下一篇: How to know line with segmentation fault in my code?