cFatal Python错误:_PyMem_DebugMalloc:在未保存GIL的情况下调用了Python内存分配器



我正在学习cpython,版本3.9.0b1,但最近我的学习因Python致命错误而中断,该错误不允许Python解释器在所有中工作

以下是Python致命错误的说明:

hatim@hatim-HP-630-Notebook-PC:~/Desktop/cpython$ ./python
Python 3.11.0a3+ (heads/main-dirty:6ca78affc8, Jan 19 2022, 11:14:50) [GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print()
Fatal Python error: _PyMem_DebugMalloc: Python memory allocator called without holding the GIL
Python runtime state: initialized
Current thread 0x00007f99b0867280 (most recent call first):

<no Python frame>
[1]    3660 abort (core dumped)  ./python

如何编译Python

我的一个朋友(gitclone(为我提供了源代码,我将其重命名为cpython.zip

我将源提取到名为cpython的目录

cd~/home/hatim/cpython

1.在文件configure,config.guess,config.sub中,我删除了放在他们shebangs中的一个空间,因为这个空间会产生这个错误

zsh:/configure:错误的解释器:/bin/sh^M:没有这样的文件或目录

所有3个文件都有这个shebang:#/bin/sh

两者之间有间隔!和/

2.found|xargs-I f dos2unix f

3.autoconf

4../configure--使用pydebug

5.make,最近我添加了-j

6.make-jaltinstall

这样这个版本就不会干扰我的其他蟒蛇

这个Python致命错误以前从未出现过,尽管我在计算机上编译了10多次相同的cpython,但它只是昨天发生的。我想我可能破坏了cpython代码,但我删除了整个(cpython(目录,解压缩了源代码并重新编译,但致命错误一直显示在上

我知道的不多,但我试图找出问题所在,我知道的是:

此致命错误是由cpython/Objects/obmalloc.c中的_PyMem_DebugCheckGIL引起的,当cpython/Python/pystate.c中的PyGILState_Check返回0 时会引发此错误

in file cpython/Objects/obmalloc.c
int PyGILState_Check(void)
{

struct _gilstate_runtime_state *gilstate = &_PyRuntime.gilstate;
if (!gilstate->check_enabled) {
printf("n!gilstate->check_enabledn");
return 1;
}
if (!PyThread_tss_is_created(&gilstate->autoTSSkey)) {
printf("n!PyThread_tss_is_created(&gilstate->autoTSSkey)n");
return 1;
}
printf("%d", (gilstate != NULL));
PyThreadState *tstate = _PyRuntimeGILState_GetThreadState(gilstate);
if (tstate == NULL) {
printf("ntstate == NULLn");
return 0;
}
return (tstate == _PyGILState_GetThisThreadState(gilstate));
}
in file cpython/Python/pystate.c
static inline void
_PyMem_DebugCheckGIL(const char *func)
{
if (!PyGILState_Check()) {
_Py_FatalErrorFunc(func,
"Python memory allocator called "
"without holding the GIL");
}
}

在我的情况下,PyGILState_Check返回0,因为tstate为NULL

我运行Ubuntu 20.04 LTS 64位

那么,该怎么办呢?提前感谢

我正在学习cpython,版本3.9.0b1

不,你不是。你的轨迹清楚地显示

Python 3.11.0a3+ (heads/main-dirty:6ca78affc8

这意味着您使用的是基于6ca78affc8的Python版本,然后在工作树(-dirty(中进行修改。

我的一个朋友(gitclone(为我提供了源代码,我将其重命名为cpython.zip

为什么不自己克隆源代码,或者至少使用源代码tarball?如果你必须更改换行符,听起来你的朋友使用了一台配置错误的Git的Windows机器;有益的";将换行符更改为Windows CRLF。

此外,错误的屏幕截图显然有不同于print()的代码。我不认为Python会打印出";时间结束";默认情况下。


如果您想学习Python,请使用预编译版本。既然你使用的是Ubuntu 20.04,那么

apt install python3-dev

要获得所有的细节,您需要使用Python并编写Python扩展。

如果你真的想从源代码编译CPython,例如破解它的内部,那么你真的应该使用git签出它——如果不需要其他东西,就可以跟踪你自己的本地更改。

相关内容

最新更新