Message365913
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));
Py_VISIT(self->_abc_registry);
Py_VISIT(self->_abc_cache);
Py_VISIT(self->_abc_negative_cache);
$ ./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:05 | vstinner | set | recipients:
+ vstinner, corona10 |
2020-04-07 16:50:05 | vstinner | set | messageid: <1586278205.49.0.505383041785.issue40149@roundup.psfhosted.org> |
2020-04-07 16:50:05 | vstinner | link | issue40149 messages |
2020-04-07 16:50:04 | vstinner | create | |
|