There are different ways to fix this issue:
* (A) Rewrite threading.enumerate() in C with code which cannot trigger a GC collection
* (B) Disable temporarily the GC
* (C) Use a reentrant lock (PR 26727)
(A) The problem is that functions other than threading.enumerate()
also rely on this lock, like threading.active_count(). I would prefer to not have to rewrite "half" of threading.py in C. Using a RLock is less intrusive.
(B) This is a simple and reliable option. But gc.disable() is process-wide: it affects all Python threads, and so it might have surprising side effects. Some code might rely on the current exact GC behavior. I would prefer to not disable the GC temporarily. |