import threading from collections import OrderedDict from random import randrange import time c = 10000 h = 0 d = OrderedDict([(k, k) for k in range(c)]) class C: def __hash__(self): global c, h, d for i in range(c, c+100000): d[i] = 0 c += 100000 h += 1 return h def f(): global d time.sleep(1) d[C()] = d th = [0] * 10 for i in range(1, 10): th[i] = threading.Thread(target=f, args=()) th[i].start() for i in range(1, 10): th[i].join()