Threading Pool Event()
Aahz
aahz at pythoncraft.com
Fri Jul 18 18:47:13 EDT 2003
More information about the Python-list mailing list
Fri Jul 18 18:47:13 EDT 2003
- Previous message (by thread): Threading Pool Event()
- Next message (by thread): Threading Pool Event()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In article <NDZRa.273$vD1.11889 at nnrp1.ozemail.com.au>, Graeme Matthew <gsmatthew at ozemail.com.au> wrote: > >Thanks, ive actually been using your OSCON slides which have helped a >lot. So it technically correct that all worker threads in a thread >pool are either doing some work or polling the queue to find out if >there is a job to process ? The whole point is that it *doesn't* poll. It blocks on a lock internal to the Queue object. That makes it extremely efficient. >eg: (pseudocodish :-)) > >def run(self): > > while 1: > > self.lock.acquire() > > if QueueManager.HasJob: > job = QueueManager.GetFreeJob() > __processJob(job) > > self.lock.release() > > def __processJob(self): > > blah blah blah ..... Nope, it's even simpler than that: def run(self): done = False while not done: job = q.get() if job.done: done = True else: __processJob(job) The Queue handles all the locks for you. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ A: No. Q: Is top-posting okay?
- Previous message (by thread): Threading Pool Event()
- Next message (by thread): Threading Pool Event()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list