¡@

Home 

python Programming Glossary: lockedset

How to make built-in containers (sets, dicts, lists) thread safe?

http://stackoverflow.com/questions/13610654/how-to-make-built-in-containers-sets-dicts-lists-thread-safe

I could come up with from threading import Lock class LockedSet set A set where add and remove are thread safe def __init__.. a lock self._lock Lock # Call the original __init__ super LockedSet self .__init__ args kwargs def add self elem self._lock.acquire.. args kwargs def add self elem self._lock.acquire try super LockedSet self .add elem finally self._lock.release def remove self elem..