3 ms·
This is tricky because dictionaries need to call __hash__ which can run arbitrary Python code, so it's non-trivial to make the dictionary threadsafe.
by raymondh 15y ago
This is tricky because dictionaries need to call __hash__ which can run arbitrary Python code, so it's non-trivial to make the dictionary threadsafe.
- kingkilr 15y ago__eq__ as well
- dfox 15y agoIt's perfectly possible and even reasonable to call __hash__ before acquiring lock on the dictionary (and cache keys' hashes for data in the dictionary). On the other hand, when almost every object is backed by dictionary, the locking has to be very fast, which seems to me like almost unsolvable problem.
- lobster_johnson 15y agoJust make __hash__() wrap the underlying dict in a thread-safe one that delegates the calls.