bpo-46070: Revert "bpo-36854: Move _PyRuntimeState.gc to PyInterpreterState (GH-17287)" by vstinner · Pull Request #30564 · python/cpython
BTW, do we have any sort of reproducer for which we can add a test?
So far, I was only able to reproduce the crash on Windows with Python 3.9 using win_py399_crash_reproducer.py script of https://bugs.python.org/issue46070 I failed to write a reliable reproducer which works on any platform.
I didn't fully understand the root issue. My theory is that an object is shared by two interprereter. The first interpreter runs a GC collection which traverses this shared object, an object finalizer releases the GIL. Now the second interpreter gets the GIL and also runs a GC collection which traverses the same shared object.
The problem is that the PyGC_Head header cannot be modified by two interpreters in parallel: data races are likely and Python does crash somehow.
Since the bug is a crash and so far nobody managed to fully understand it, IMO it's safer to revert the change for now.