TypeError:'coroutine' object is not iterable

4,285 views
Skip to first unread message

Cong Wang

unread,
Feb 16, 2017, 2:49:29 AM2/16/17
to python-...@googlegroups.com, Ben Darnell
Hi
Here comes the  following problem in my code ,is there something wrong with my usage of async-await corroutine?
the error:内嵌图片 2

in the multiserver.py ,perhaps the read_in_chunks_pos function.

I am so eager to know that.
Thanks!

Best regards,
cong
Message has been deleted

whatisn...@googlemail.com

unread,
Feb 16, 2017, 7:44:47 AM2/16/17
to Tornado Web Server, b...@bendarnell.com
Hi Cong,

Why are you using async and await? Native coroutines are still very new, they were introduced in Python 3.5 and Tornado 4.3, and as tempting as it may seem to want to use them, why not stick with the tried and tested @gen.coroutine and yield pattern?

Anyway sorry for not answering your question directly, but if you stick with @gen.coroutine, then just use raise gen.Return(...) to get the behaviour you are after.

Hope this helps.

W.

Ben Darnell

unread,
Feb 19, 2017, 7:29:56 PM2/19/17
to Cong Wang, python-...@googlegroups.com
I think what you want is for read_in_chunks and read_in_chunks_pos to be generators, not coroutines. Use `def` instead of `async def` and `yield` instead of `await` (but leave the `get()` coroutines as they are). `async def` is a replacement for generators wrapped with @gen.coroutine, but it can't replace all generators. 

-Ben

On Thu, Feb 16, 2017 at 2:49 AM Cong Wang <congfa...@gmail.com> wrote:
Hi
Here comes the  following problem in my code ,is there something wrong with my usage of async-await corroutine?
the error:image.png
Reply all
Reply to author
Forward
0 new messages