Threading Pool Event()

Graeme Matthew gsmatthew at ozemail.com.au
Fri Jul 18 21:29:44 EDT 2003


ok still a bit confused sorry .... first attempt at a thread pool

Am I correct in saying that each thread runs in a continious loop

each thread calls queue.get. The get method will block and not return
anything until an item is placed into it. When an item is placed into it,
one of the threads will get assinged a job i.e the first one that happens to
be in use during the cycle ?

The job is returned to the thread, it runs with the job and does all the
processing then returns and calls queue.get again and waits for a job to
become available ?

When placing a job via Queue.put() one must acquire a lock place it and then
release it

Am i aslo correct in saying that queue is actually doing the blocking and
controls which thread gets the job ?

Lastly, sorry for all the questions, surely the CPU usage is the same when
the queue is waiting for jobs and when the threads are polling as theyre all
in one process anyway

thanks very much for your help

Graeme
Am i getting this or am i way off :-)


"Graeme Matthew" <gsmatthew at ozemail.com.au> wrote in message
news:NDZRa.273$vD1.11889 at nnrp1.ozemail.com.au...
> Aahz
>
> 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 ?
>
> 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 .....
>
>
> many thanks ......
> "Aahz" <aahz at pythoncraft.com> wrote in message
> news:bf8ri5$cs7$1 at panix1.panix.com...
> > In article <0tRRa.212$vD1.8077 at nnrp1.ozemail.com.au>,
> > Graeme Matthew <gsmatthew at ozemail.com.au> wrote:
> > >
> > >I just cannot seem to find any documentation that shows an example of
> > >using the factory method Event() in threads. I have a thread pool and
> > >if there are no jobs in a Queue I want them to wait for something to
> > >be inserted. When a job is inserted I want to send an Event, the first
> > >thread that picks it up runs with the job the rest wait for another
> > >insert Event.
> >
> > Given that you're already using a Queue, there is no, repeat NO, reason
> > for using an Event.  Just have your threads block on the Queue.
> > --
> > Aahz (aahz at pythoncraft.com)           <*>
> http://www.pythoncraft.com/
> >
> > A: No.
> > Q: Is top-posting okay?
>
>






More information about the Python-list mailing list