gpt4 book ai didi

python - 带有 C 扩展名的 Python 中的总线错误

转载 作者:太空宇宙 更新时间:2023-11-04 00:07:57 25 4
gpt4 key购买 nike

最近我一直致力于用 C 扩展编写 python 模块。(python2.7, gcc 4.1.2)一旦完成并进行测试。我发现以下总线错误。

有人知道为什么吗?

p.s 在我收到这个错误之前。我修复了

中描述的“返回 Py_False 相关错误”

Application gives segmentation fault randomly in python extension functions in c++

核心由 python2.7 app.py --debug=False --multi_slaves=True 生成

Program terminated with signal 7, Bus error.
#0 0x0000003d22272cf1 in _int_malloc () from /lib64/libc.so.6
(gdb) where
#0 0x0000003d22272cf1 in _int_malloc () from /lib64/libc.so.6
#1 0x0000003d22274e4e in malloc () from /lib64/libc.so.6
#2 0x00000000004d3069 in _PyObject_GC_Malloc (basicsize=<value optimized out>) at Modules/gcmodule.c:1445
#3 0x000000000046408c in PyType_GenericAlloc (type=0x768360, nitems=0) at Objects/typeobject.c:753
#4 0x00000000004477ec in dict_new (type=0x3d225539e0, args=, kwds=0x7fff8dcb4eb0) at Objects/dictobject.c:2301
#5 0x00000000004661c3 in type_call (type=0x3d225539e0, args=0x2b3e5a521050, kwds=0x2239bca0) at Objects/typeobject.c:721
#6 0x00000000004189cd in PyObject_Call (func=0x768360, arg=0x2b3e5a521050, kw=0x2239bca0) at Objects/abstract.c:2529

c 扩展代码如下所示

static PyObject* analyze( PyObject *self, PyObject *args )
{
int ret;
char* in;

// global variables : void* obj, char* outbuf, int outbuf_size;
if (PyArg_ParseTuple(args, "s", &in)){
ret = process(obj, in, outbuf, outbuf_size);
if ( ret == SUCCESS ) {
PyObject* py_out = PyString_FromString(outbuf);
return py_out;
} else {
Py_INCREF(Py_False);
return Py_False;
}
} else {
Py_INCREF(Py_False);
return Py_False;
}
}

~

最佳答案

FWIW 我从 python 程序中收到总线错误。原来是跟它分配共享内存有关。我在 docker 容器中运行它并且必须设置 docker run ... --shm_size=1g 如下所述: https://goblincoding.com/2018/02/19/docker-bus-error-no-space-left-on-device/

关于python - 带有 C 扩展名的 Python 中的总线错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16054204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com