Queue cleanup

EW ericwoodworth at gmail.com
Wed Aug 11 13:57:14 EDT 2010


On Aug 11, 1:55 pm, MRAB <pyt... at mrabarnett.plus.com> wrote:
> EW wrote:
>
> [snip]
>
>
>
> > So here the P2 thread has ended and gone away but I still have his
> > Queue lingering.
>
> > So on a thread I can use is_alive() to check status and use join() to
> > clean up but I don't see any analogous functionality for Queues.  How
> > do I kill them?  I thought about putting a suicide message on the
> > Queue and then C1 would read it and set the variable to None but i'm
> > not sure setting the variable to None actually makes the Queue go
> > away.  It could just end up sitting in memory unreferenced - and
> > that's not good.  Additionally, I could have any number of consumer
> > threads reading that Queue so once the first one get the suicide note
> > the other consumer threads never would.
>
> > I figure there has to be an elegant way for managing my Queues but so
> > far I can't find it.  Any suggestions would be appreciated and thanks
> > in advance for any help.
>
> An object will be available for garbage collection when nothing refers
> to it either directly or indirectly. If it's unreferenced then it will
> go away.
>
> As for the suicide note, if a consumer sees it then it can put it back
> into the queue so other consumers will see it and then forget about the
> queue (set the variable which refers to the queue to None, or, if the
> references are in a list, delete it from the list).

Ok great.  I wasn't sure about the Garbage collection part of it.
That's actually pretty easy.

Thanks!



More information about the Python-list mailing list