Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33854 > unrolled thread

Why queue.empty() returns False even after put() is called?

Started byPeng Yu <pengyu.ut@gmail.com>
First post2012-11-23 08:57 -0800
Last post2012-11-23 11:53 -0700
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Why queue.empty() returns False even after put() is called? Peng Yu <pengyu.ut@gmail.com> - 2012-11-23 08:57 -0800
    Re: Why queue.empty() returns False even after put() is called? MRAB <python@mrabarnett.plus.com> - 2012-11-23 18:53 +0000
    Re: Why queue.empty() returns False even after put() is called? Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-23 11:53 -0700

#33854 — Why queue.empty() returns False even after put() is called?

FromPeng Yu <pengyu.ut@gmail.com>
Date2012-11-23 08:57 -0800
SubjectWhy queue.empty() returns False even after put() is called?
Message-ID<f5b194cd-cf32-4c3b-a909-8c53a72a4b64@b12g2000vbg.googlegroups.com>
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()


Regards,
Peng

[toc] | [next] | [standalone]


#33862

FromMRAB <python@mrabarnett.plus.com>
Date2012-11-23 18:53 +0000
Message-ID<mailman.239.1353696834.29569.python-list@python.org>
In reply to#33854
On 2012-11-23 16:57, 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()
>
It works correctly for me.

[toc] | [prev] | [next] | [standalone]


#33863

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-11-23 11:53 -0700
Message-ID<mailman.240.1353696850.29569.python-list@python.org>
In reply to#33854
On Fri, Nov 23, 2012 at 9:57 AM, Peng Yu <pengyu.ut@gmail.com> 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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web