[Tutor] Python performance resources & resouce usage hints

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Apr 7 20:27:50 CEST 2006

On Fri, 7 Apr 2006, Kent Johnson wrote:

> Hugo González Monteverde wrote:
> > You are not using the optional timeout and blocking which 'get' provides (!)
> >
> > Try setting it and see your CPU usage go down. This will implement
> > blocking, and the queue will be used as soon as data is there.	Set block
> > to True and a timeout if you need to use it (looks like you only need
> > blocking)
> >
> >          while True:
> >               try:
> >                  data = self.queue.get(True)
> >                  self.DAO.send_data(data)
> I think he will need the timeout too, otherwise the shutdown flag will
> only be checked when there is work which is probably not what he wants.

This could be fixed: when setting the 'shutdown' flag, also push a
sentinel piece of data into the queue.  That'll wake the thread back up,
and that'll give it the opportunity to process a shutdown.

The thread here:


has some more examples of this.

Hope this helps!

More information about the Tutor mailing list