Answer the question
In order to leave comments, you need to log in
How to set blocking for only some threads?
I have some code that should be locked only for some threads
name = order.id
lock = Lock()
with lock:
change_order()
Answer the question
In order to leave comments, you need to log in
Lock (aka mutex) does not deal with such things.
You can cheat a construction where each order has its own Lock, but this will either be wasteful (if you always create a Lock) or tedious (if you create it when order is accessed).
An asynchronous approach can help, but it will require almost a complete code rewrite. Not very convenient.
In general, it is worth asking a question - is this Lock exactly a bottleneck?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question