Hi,

I updated asyncio doc of the Queue class:
https://hg.python.org/cpython/rev/ae0b4076b9ad
https://hg.python.org/cpython/rev/c4643b32cd9a

Maybe it was possible to use get/put as a function, not a coroutine,
before. And the doc was not updated. Well, now the doc should
described of Queue behaves. Thanks for the feedback.

Victor

2014-12-18 22:49 GMT+01:00 Paul Sokolovsky <[email protected]>:
> Hello,
>
> On Thu, 18 Dec 2014 22:30:19 +0100
> Victor Stinner <[email protected]> wrote:
>
>> 2014-12-18 19:30 GMT+01:00 Paul Sokolovsky <[email protected]>:
>> > "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]

Reply via email to