Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'puts': 0.07; 'python': 0.09; 'called.': 0.09; 'subject:Why': 0.09; 'thread': 0.11; 'yet.': 0.13; 'inserting': 0.16; 'non-empty': 0.16; 'run.': 0.16; 'wrote:': 0.17; 'appears': 0.18; 'load': 0.19; 'import': 0.21; 'transfers': 0.23; 'header:In-Reply-To:1': 0.25; 'thanks!': 0.26; 'am,': 0.27; 'skip:# 10': 0.27; 'message-id:@mail.gmail.com': 0.27; 'run': 0.28; 'cat': 0.29; 'queue': 0.29; 'objects': 0.29; 'fri,': 0.30; 'anybody': 0.32; 'could': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'likely': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'nov': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'should': 0.36; 'uses': 0.37; 'why': 0.37; 'item': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'most': 0.61; 'first': 0.61; 'chance': 0.61; 'become': 0.65; 'feeder': 0.84; 'skip:~ 60': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=fVrs89rUoYhl/R5sENULCiSfDkpK2sZrGYJTHg6YSj8=; b=hxvXcs8X0pWiyY2+JN+fSyACknKLr0jTgQsHtAVYh1bNNvoeAjE0OAmsd7oTKEpD0d S8ivG+vYqH8yZRvCZv+Sis0blV761h4PrTTJRstdt3cRB8yT8PuyGf5LXdWlh+zajWiQ b9siIzYq1qR2QgXsy5xBfthJBXZoYde1++euccyEOW/C3nhQ6PMxWcs22EvqENqArLiN bWMu/eEBUivJ1p8xaFO4QmYLdBVrp859rvZIGoImwimj9O16oLXz0QsZuJ0EOtPT3wva eGc2Q2dEi5GdR8lSUuY9pnGldNMFhFxnw1Bt4h7TodycKTaO8iC0F6NaRXDXnp9QVIWB Qazw== MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Fri, 23 Nov 2012 11:53:31 -0700 Subject: Re: Why queue.empty() returns False even after put() is called? To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1353696850 news.xs4all.nl 6869 [2001:888:2000:d::a6]:47120 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33863 On Fri, Nov 23, 2012 at 9:57 AM, Peng Yu wrote: > Hi, > > The empty() returns True even after put() has been called. Why it is > empty when there some items in it? Could anybody help me understand > it? Thanks! > > ~/linux/test/python/man/library/multiprocessing/Queue/empty$ cat > main.py > #!/usr/bin/env python > > import multiprocessing > > queue = multiprocessing.Queue() > print queue.empty() > queue.put(['a', 'b']) > queue.put(['c', 'd']) > print queue.empty() According to the docs, the Queue uses a background thread to load data into it: When a process first puts an item on the queue a feeder thread is started which transfers objects from a buffer into the pipe. Most likely it still appears to be empty because this thread has not had a chance to run yet. If you try inserting a time.sleep() call, you should see the queue become non-empty once the background thread has run.