我想查看Cpython中dprintf打印的日志,比如this one,但是这里只有一个dprintf的参数,如何查看这些日志?非常感谢你的帮助。
发布于 2019-01-14 03:17:54
如果您使用的是Python的发行版,那么dprintf将被剥离,并且不会记录这些语句。不可能看到它们的输出。
dprintf是一个实际上只在thread.c中定义的宏。其定义是
#ifdef Py_DEBUG
static int thread_debug = 0;
#define dprintf(args) (void)((thread_debug & 1) && printf args)
#define d2printf(args) ((thread_debug & 8) && printf args)
#else
#define dprintf(args)
#define d2printf(args)
#endif即,如果Py_DEBUG设置为和 thread_debug & 1,则使用printf将日志打印到标准输出。为此,您需要一个调试版本的Python。如果您有调试版本,则可以使用环境变量PYTHONTHREADDEBUG来控制thread_debug的值
void
PyThread_init_thread(void)
{
#ifdef Py_DEBUG
char *p = Py_GETENV("PYTHONTHREADDEBUG");
if (p) {
if (*p)
thread_debug = atoi(p);
else
thread_debug = 1;
}
#endif /* Py_DEBUG */
if (initialized)
return;
initialized = 1;
dprintf(("PyThread_init_thread called\n"));
PyThread__init_thread();
}即,对于设置为1值的变量,必须存在该变量,如果设置为例如9,这将启用dprintf和d2printf。
发布于 2019-01-14 03:16:29
我认为你需要重新编译Python才能看到这些。在配置时,给出--with-pydebug选项。它应该在标准输出上出来。您可能还需要将环境变量PYTHONTHREADDEBUG设置为1,但这不是必需的。
https://docs.python.org/3/using/cmdline.html#debug-mode-variables
https://stackoverflow.com/questions/54171954
复制相似问题