Agreed! I was at first a little confused because, from the documentation, it sounds like simply calling `get()` by itself will do something (and then you can optionally wait by yielding).
On Thursday, December 18, 2014 1:49:06 PM UTC-8, Paul Sokolovsky wrote: > > Hello, > > On Thu, 18 Dec 2014 22:30:19 +0100 > Victor Stinner <[email protected] <javascript:>> wrote: > > > 2014-12-18 19:30 GMT+01:00 Paul Sokolovsky <[email protected] > <javascript:>>: > > > "Remove and return an item from the queue. If you yield from get(), > > > wait until a item is available. If you don't yield from get() (which > > > apparently means calling it directly), it won't wait until item is > > > available (but do something else, which is underspecified)". > > > > Queue.get() and Queue.put() are not special. They must be used as any > > other coroutine: you must use them with yield-from. > > Thanks for confirming this. > > > > > Maybe the link on "This method is a coroutine." must explain better > > how a coroutine must be used? > > Well, if that is to be applied, then probably consistently to every > function/method which is coroutine. But that may be too verbose, and > one might expect that someone using asyncio knows what a coroutine is > and how to use it (or will look it up on their own). > > My specific concern is with the descriptions of get() and post() > methods. > > Specifically, I would propose at > https://docs.python.org/3/library/asyncio-sync.html#asyncio.Queue.get > to replace > > " > Remove and return an item from the queue. > > If you yield from get(), wait until a item is available. > > This method is a coroutine. > " > > with: > > " > Remove and return an item from the queue. If queue does not have any > items, wait until an item is available. > > This method is a coroutine. > " > > Ditto for put(). > > > Thanks. > > > > > Example of code: > > --- > > import asyncio > > q = asyncio.Queue() > > q.get() > > --- > > > > Output when running the code in debug mode: > > --- > > $ PYTHONASYNCIODEBUG=1 python3.4 test.py > > <CoroWrapper Queue.get() running at > > /home/haypo/prog/python/default/Lib/asyncio/queues.py:160, created at > > x.py:4> was never yielded from > > Coroutine object created at (most recent call last): > > File "tes.py", line 3, in <module> > > q.get() > > --- > > > > You get the same error with a random coroutine: > > --- > > import asyncio > > > > @asyncio.coroutine > > def transaction(): > > yield from asyncio.sleep(1) > > print("transation done") > > > > transaction() > > --- > > > > Victor > > > > -- > Best regards, > Paul mailto:[email protected] <javascript:> >
