Queuing methods to be run on an object by different threads in Python
- by Ben
Let's say I have an object who's class definition looks like:
class Command:
foo = 5
def run(self, bar):
time.sleep(1)
self.foo = bar
return self.foo
If this class is instantiated once, but different threads are hitting its run method (via an HTTP request, handled separately) passing in different args, what is the best method to queue them? Can this be done in the class definition itself?