2 ms·
The problem is that `lock = Lock()` is shared across all instances of the class, which creates contention if there are many of them. To solve this you need to s
by ajkjk 5y ago
The problem is that `lock = Lock()` is shared across all instances of the class, which creates contention if there are many of them. To solve this you need to save a per-instance lock, so yes to "Wait do you want the decorator, before it ever runs, to add a property self.lock".
An example usecase is writing a @cached decorator that behaves well in multithreaded programs and can be used on classes that have many instances, with the caching happening per-instance.