import threading, time class SlowEq: def __init__(self, i): self. i = i def __hash__(self): return hash(self.i) def __eq__(self, other): time.sleep(0.001) return self.i == other.i A = set(SlowEq(i) for i in range(100)) B = frozenset(SlowEq(i) for i in range(100)) C = set([B]) stop = False def set_test(): global stop while not stop: if A not in C: stop = True raise RuntimeError('A not in C') print('A in C?', A in C) print() thread = threading.Thread(target=set_test) thread.start() set_test()