Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'irc': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wrapper': 0.09; '#python': 0.16; 'attribute:': 0.16; 'deque': 0.16; 'limiting': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'skipping': 0.16; 'wrote:': 0.18; 'meant': 0.20; 'solution.': 0.20; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'adds': 0.24; 'entries': 0.24; 'received:comcast.net': 0.24; "shouldn't": 0.24; 'subject:like': 0.24; 'mon,': 0.24; 'question': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'testing': 0.29; 'chris': 0.29; 'am,': 0.29; 'dec': 0.30; 'posting': 0.31; 'directly,': 0.31; 'quite': 0.32; 'noticed': 0.34; 'could': 0.34; 'subject:with': 0.35; 'knows': 0.35; 'but': 0.35; 'should': 0.36; 'list': 0.37; 'needed': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'channel': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'first': 0.61; 'actually,': 0.84; 'batchelder': 0.84; 'mistakenly': 0.91; 'from.': 0.93; 'directly.': 0.95; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: how to implement a queue-like container with sort function Date: Mon, 02 Dec 2013 07:26:01 -0500 References: <0c445e44-25c7-42b9-8c62-c30428261251@googlegroups.com> <39b48b0b-5c0a-42d9-922f-27987386764b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: c-50-133-228-126.hsd1.ma.comcast.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385987179 news.xs4all.nl 15974 [2001:888:2000:d::a6]:41438 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60863 On 12/2/13 7:04 AM, Chris Angelico wrote: > On Mon, Dec 2, 2013 at 10:58 PM, Ned Batchelder wrote: >> Yes, a Queue object has a queue attribute: >> >> >>> import Queue >> >>> q = Queue.Queue() >> >>> q.queue >> deque([]) >> >> But you shouldn't use it. It's part of the implementation of Queue, not >> meant for you to use directly. In particular, if you use it directly, you >> are skipping all synchronization, which is the main reason to use a Queue in >> the first place. > > I should apologize here; when the OP said "queue", I immediately > noticed that I could import that and use it, and mistakenly started my > testing on that, instead of using the deque type. It's deque that > should be used here. Queue is just a wrapper around deque that adds > functionality that has nothing to do with what's needed here. > > ChrisA > Actually, I had a long conversation in the #python IRC channel with the OP at the same time he was posting the question here, and it turns out he knows exactly how many entries are going into the "queue", so a plain-old list is the best solution. I don't know quite where the idea of limiting the number of entries came from. --Ned.