"pyo" macro from gdbinit (see #3631) uses _PyObject_Dump() to display an object. This function calls (indirectly) string_print() to display one line of text. But if the GIL is released (I guess it's the GIL or is it called the "thread state"?), gdb crashs Python: object : Fatal Python error: PyEval_SaveThread: NULL tstate Program received signal SIGABRT, Aborted. 0xffffe410 in __kernel_vsyscall () Workaround: ensure GIL before Py_BEGIN_ALLOW_THREADS... That sounds ugly but it works :-) So I propose to enable it in debug mode (#ifdef Py_DEBUG) with a patch. I guess that the issue is very specific to (gdb) debugging and should not affect normal usage of Python. That's why I choosed to enable it only in debug mode.
I once fell into the same issue, but the patch should modify _PyObject_Dump(), around the call to PyObject_Print. string_print() is not the only function called by _PyObject_Dump, by far... And beware that many people routinely run python in "debug mode" outside gdb, for example during development. That's why it's better to modify _PyObject_Dump only; we can be sure that it only affects a debugger session.
I would love to have this patch, along with those of #3631 and #3610, included in Misc as diffs. This would make it easier to get the improved functionality in a new development box, besides allowing distributions to apply them at will.