This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients corona10, vstinner
Date 2020-04-07.16:50:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
In _abcmodule_exec(), when _abc_data type is created, it's created with refcnt=3:
* 1 strong reference (normal)
* +1 ref from tp_dict['__new__'] slot
* +1 ref from tp_mro

type_traverse() visits tp_dict and tp_mro, so it's fine.

In Py_EndInterpreter(), PyInterpreterState_Clear() clears os.register_atfork() callbacks which were one of the last references to _abc_data type. The first call to _PyGC_CollectNoFail() destroys _abc_data *instances* but not the _abc_data type.

The following patch works around the issue:

diff --git a/Modules/_abc.c b/Modules/_abc.c
index 1efc98bf72..410dbcf96a 100644
--- a/Modules/_abc.c
+++ b/Modules/_abc.c
@@ -54,6 +54,7 @@ typedef struct {
 static int
 abc_data_traverse(_abc_data *self, visitproc visit, void *arg)
+    Py_VISIT(Py_TYPE(self));

$ ./python -m test -R 3:3 test_threading -m test.test_threading.SubinterpThreadingTests.test_threads_join_2
Tests result: SUCCESS

I'm not sure why Py_VISIT(Py_TYPE(self)) is needed. Maybe it's a regression caused by commit 364f0b0f19cc3f0d5e63f571ec9163cf41c62958 of bpo-35810.

It sems like the GC doesn't take in account that instances of types allocated on the heap (if type->tp_flags has the Py_TPFLAGS_HEAPTYPE flag) hold a strong refeference to the type (PyObject.ob_type).

I created bpo-40217: "The garbage collector doesn't take in account that objects of heap allocated types hold a strong reference to their type".
Date User Action Args
2020-04-07 16:50:05vstinnersetrecipients: + vstinner, corona10
2020-04-07 16:50:05vstinnersetmessageid: <>
2020-04-07 16:50:05vstinnerlinkissue40149 messages
2020-04-07 16:50:04vstinnercreate