Queuing methods to be run on an object by different threads in Python

Posted by Ben on Stack Overflow See other posts from Stack Overflow or by Ben
Published on 2010-04-15T03:18:05Z Indexed on 2010/04/15 3:23 UTC
Read the original article Hit count: 272

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?

© Stack Overflow or respective owner

Related posts about python

Related posts about multithreading