2 回答

TA贡献1802条经验 获得超10个赞
如果您有 Python 的发布版本,则dprintfs 将被剥离,并且这些语句不会记录日志。不可能看到它们的输出。
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设置了and thread_debug & 1,则使用printf,将日志打印到标准输出。为此,您需要一个 Python 的调试版本。如果您有调试版本,则thread_debug可以使用环境变量控制 的值PYTHONTHREADDEBUG:
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。
添加回答
举报