Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33866
| Date | 2012-11-24 09:19 +1100 |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Subject | Re: Why queue.empty() returns False even after put() is called? |
| References | <CALwzid=JtEf30+JaqUN9M2we21mGQiWMGuQ6XR2XJ+-=PCY7Yw@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.243.1353709191.29569.python-list@python.org> (permalink) |
On 23Nov2012 11:53, Ian Kelly <ian.g.kelly@gmail.com> wrote: | On Fri, Nov 23, 2012 at 9:57 AM, Peng Yu <pengyu.ut@gmail.com> wrote: | > 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. Conversely, might it not appear empty because the objects have been thrown at the pipe already, appearing to have been consumed? Or is there end-to-end handshaking controlling what .empty() tests? (Though again, the far end may have grabbed them already too.) -- Cameron Simpson <cs@zip.com.au> The ZZR-1100 is not the bike for me, but the day they invent "nerf" roads and ban radars I'll be the first in line......AMCN
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Why queue.empty() returns False even after put() is called? Cameron Simpson <cs@zip.com.au> - 2012-11-24 09:19 +1100
csiph-web