bpo-31321: Fix traceback.clear_frames() by vstinner · Pull Request #3262 · python/cpython (original) (raw)
This is making clear_frames() a potentially O(n**2) operation.
Sorry, I don't know well how traceback objects are created. I didn't even know that you can have two tracebacks objects linked together.
I added a "seen = set()" to prevent iterating twice on the same frame chain. Does it solve your O(n**2) issue?
I also used my example attached to the bpo to enhance the existing unit test.