Issue #7105:  weak dict iterators are fragile because of unpredictable GC runs
Backport the fix from pyton 3.x for this issue.