[Python-Dev] More fun with Python shutdown

Thomas Heller theller at python.net
Tue Nov 11 15:22:43 EST 2003


"Tim Peters" <tim.one at comcast.net> writes:

> Jim (Fulton) refactored oodles of Zope3 to make heavier use of weak
> references.  Now Zope3 dies with a segfault when it's shut down, which makes
> its adoption of Python 2.3.2 a bit less attractive <wink>.
>
> The problem isn't really understood.  I hope that once it is, there will be
> a simple way to avoid it under 2.3.2.  Jim filed a bug report with a fix to
> the symptom here:
>
>     http://www.python.org/sf/839548

Is the problem I currently have the same, I also use weakrefs (although
Jim's patch doesn't seem to help)?

It is triggered when I have set the gc threshold to small values in a
2.3.2 debug build under Windows.  When some containers in my program are
destroyed Python crashes with an access violation in
_Py_ForgetReference() because op->_ob_next and
_op->_ob_prev are both NULL:

  void
  _Py_ForgetReference(register PyObject *op)
  {
  #ifdef SLOW_UNREF_CHECK
          register PyObject *p;
  #endif
        if (op->ob_refcnt < 0)
                Py_FatalError("UNREF negative refcnt");
        if (op == &refchain ||
            op->_ob_prev->_ob_next != op || op->_ob_next->_ob_prev != op)
                Py_FatalError("UNREF invalid object");

First I suspected buggy gc support in an extension module I have but the
crash also occurrs when I remove it.

Thomas

PS: Here is the stack trace as displayed an MSVC6:

_Py_ForgetReference(_object * 0x01101bd0) line 2001 + 15 bytes
_Py_Dealloc(_object * 0x01101bd0) line 2021 + 9 bytes
delete_garbage(_gc_head * 0x0012d640, _gc_head * 0x1e1783e0) line 516 + 81 bytes
collect(int 0) line 625 + 13 bytes
collect_generations() line 673 + 9 bytes
_PyObject_GC_Malloc(unsigned int 24) line 1061
_PyObject_GC_New(_typeobject * 0x1e186c00 _PyListIter_Type) line 1070 + 12 bytes
list_iter(_object * 0x01101c08) line 2414 + 10 bytes
PyObject_GetIter(_object * 0x01101c08) line 2161 + 7 bytes
eval_frame(_frame * 0x008aa278) line 2077 + 9 bytes
PyEval_EvalCodeEx(PyCodeObject * 0x00b8be40, _object * 0x00b7af50, _object * 0x00000000, _object * * 0x008e3808, int 0, _object * * 0x008e3808, int 1, _object * * 0x00000000, int 0, _object * 0x00000000) line 2663 + 9 bytes
fast_function(_object * 0x00b966c0, _object * * * 0x0012da24, int 2, int 0, int 1) line 3532 + 68 bytes
call_function(_object * * * 0x0012da24, int 256) line 3458 + 25 bytes
eval_frame(_frame * 0x008e36a8) line 2116 + 13 bytes
PyEval_EvalCodeEx(PyCodeObject * 0x00b8bb28, _object * 0x00b7af50, _object * 0x00000000, _object * * 0x01117d6c, int 1, _object * * 0x00000000, int 0, _object * * 0x0111712c, int 1, _object * 0x00000000) line 2663 + 9 bytes
function_call(_object * 0x011028d0, _object * 0x01117d58, _object * 0x00000000) line 509 + 64 bytes
PyObject_Call(_object * 0x011028d0, _object * 0x01117d58, _object * 0x00000000) line 1755 + 15 bytes
PyObject_CallFunction(_object * 0x011028d0, char * 0x1e1c63b8) line 1797 + 15 bytes
handle_callback(_PyWeakReference * 0x01114f68, _object * 0x011028d0) line 684 + 18 bytes
PyObject_ClearWeakRefs(_object * 0x01101bd0) line 750 + 13 bytes
subtype_dealloc(_object * 0x01101bd0) line 656 + 9 bytes
_Py_Dealloc(_object * 0x01101bd0) line 2022 + 7 bytes
list_dealloc(PyListObject * 0x00a0f930) line 214 + 153 bytes
_Py_Dealloc(_object * 0x00a0f930) line 2022 + 7 bytes
dict_dealloc(_dictobject * 0x01100380) line 708 + 108 bytes
_Py_Dealloc(_object * 0x01100380) line 2022 + 7 bytes
subtype_dealloc(_object * 0x010f4f18) line 680 + 81 bytes
_Py_Dealloc(_object * 0x010f4f18) line 2022 + 7 bytes
PyDict_DelItem(_object * 0x01100428, _object * 0x00a73368) line 583 + 81 bytes
PyObject_GenericSetAttr(_object * 0x010f4ee0, _object * 0x00a73368, _object * 0x00000000) line 1529 + 13 bytes
PyObject_SetAttr(_object * 0x010f4ee0, _object * 0x00a73368, _object * 0x00000000) line 1289 + 18 bytes
eval_frame(_frame * 0x008f8b38) line 1760 + 15 bytes
PyEval_EvalCodeEx(PyCodeObject * 0x00b48d90, _object * 0x00b42188, _object * 0x00000000, _object * * 0x00893c70, int 5, _object * * 0x00893c84, int 0, _object * * 0x00000000, int 0, _object * 0x00000000) line 2663 + 9 bytes
fast_function(_object * 0x00b57980, _object * * * 0x0012e070, int 5, int 5, int 0) line 3532 + 68 bytes
call_function(_object * * * 0x0012e070, int 4) line 3458 + 25 bytes
eval_frame(_frame * 0x00893b08) line 2116 + 13 bytes
fast_function(_object * 0x00b79fb0, _object * * * 0x0012e218, int 5, int 5, int 0) line 3518 + 9 bytes
call_function(_object * * * 0x0012e218, int 4) line 3458 + 25 bytes
eval_frame(_frame * 0x008958e8) line 2116 + 13 bytes
PyEval_EvalCodeEx(PyCodeObject * 0x00b48188, _object * 0x00b42188, _object * 0x00000000, _object * * 0x011194cc, int 4, _object * * 0x00000000, int 0, _object * * 0x00000000, int 0, _object * 0x00000000) line 2663 + 9 bytes
function_call(_object * 0x00b4cea8, _object * 0x011194b8, _object * 0x00000000) line 509 + 64 bytes
PyObject_Call(_object * 0x00b4cea8, _object * 0x011194b8, _object * 0x00000000) line 1755 + 15 bytes
PyEval_CallObjectWithKeywords(_object * 0x00b4cea8, _object * 0x011194b8, _object * 0x00000000) line 3346 + 17 bytes
PyObject_CallObject(_object * 0x00b4cea8, _object * 0x011194b8) line 1746 + 15 bytes
_CallPythonObject(void * 0x0012e3e4, char * 0x10010e00, _object * 0x00b4cea8, _object * 0x00a9fbc0, void * * 0x0012e41c) line 178 + 14 bytes
i_CallPythonObject(_object * 0x00b4cea8, _object * 0x00a9fbc0, void * * 0x0012e40c) line 213 + 26 bytes





More information about the Python-Dev mailing list