Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'coroutine' object is not iterable #122

Closed
oleksandr-kuzmenko opened this issue Dec 6, 2017 · 20 comments
Closed

'coroutine' object is not iterable #122

oleksandr-kuzmenko opened this issue Dec 6, 2017 · 20 comments

Comments

@oleksandr-kuzmenko
Copy link

  • uvloop version: 0.9.1
  • Python version: 3.6
  • Platform: Ubuntu Xenial

Version 0.9.1:
I got an error

 File "/app/app/<***>/utils.py", line 35, in <***>
    async with app['client_session'].get(url) as response:
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/client.py", line 690, in __aenter__
    self._resp = yield from self._coro
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/client.py", line 267, in _request
    conn = yield from self._connector.connect(req)
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/connector.py", line 402, in connect
    proto = yield from self._create_connection(req)
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/connector.py", line 748, in _create_connection
    _, proto = yield from self._create_direct_connection(req)
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/connector.py", line 831, in _create_direct_connection
    req=req, client_error=client_error)
  File "/usr/local/lib/python3.6/dist-packages/aiohttp/connector.py", line 796, in _wrap_create_connection
    return (yield from self._loop.create_connection(*args, **kwargs))
TypeError: 'coroutine' object is not iterable

Version 0.8.1:
Not reproduced

The error does not depend on other libraries.

@Sherlock-Holo
Copy link

Sherlock-Holo commented Dec 6, 2017 via email

@1st1
Copy link
Member

1st1 commented Dec 7, 2017

Did you install uvloop via pip? Do you use any other packages that are compiled with Cython?

@oleksandr-kuzmenko
Copy link
Author

oleksandr-kuzmenko commented Dec 7, 2017

yes, we use pip. and we have other packages (compiled with Cython) (for example: aiohttp, cChardet)

@oliwarner
Copy link

I get the same with Python 3.6 (stock cpython, Ubuntu 17.10) with a pip-installed uvloop

@achimnol
Copy link
Contributor

Another bump here with Python 3.6 on Ubuntu as well.

@frnkvieira
Copy link

Same here. (Python 3.6.4, Ubuntu 17.10)

@Urahara
Copy link

Urahara commented Jan 23, 2018

I facing this problem too, using aiohttp, any workaround? Snippet of my code:

            try:
                async with async_timeout.timeout(15):
                    async with self.session.get('http://example.com') as resp:
                        response = resp
                        break
            except Exception as e:

@1st1
Copy link
Member

1st1 commented Jan 23, 2018

I suspect that the bug is in Cython. Waiting for its next release to fix things.

@asvetlov
Copy link
Contributor

Have observed the same problem in our production code.
Surprisingly plain aiohttp example (without our straightforward but complex tooling built on top of aiohttp session) worked fine.

I was unable to pin down the minimal reproducible test case unfortunately.

@dyeray
Copy link

dyeray commented Jan 27, 2018

I'm having the exact same issue on my project, in this case when creating an asyncio_redis connection. It only happens if I import BeautifulSoup at the module level (so it was already imported before calling loop.create_connection()). I'm importing it at the function level as a workaround.

@codeadict
Copy link

I have this issue too with aiohttp

@1st1
Copy link
Member

1st1 commented Jan 28, 2018

Again, it looks like this is a regression in Cython. Try installing earlier uvloop versions, we'll fix it with the next Cython release.

@1st1
Copy link
Member

1st1 commented Mar 1, 2018

A new @cython.iterable_coroutine decorator has been added to Cython, which should resolve this issue. Now waiting for the next release to happen.

@em1208
Copy link

em1208 commented Mar 12, 2018

I have the same issue using uvloop 0.9.1 in python 3.5.2 with asyncio create_subprocess_exec. I hope this will be fixed soon!

@woyodb
Copy link

woyodb commented Mar 21, 2018

uvloop version: 0.9.1
Python version: 3.6.4
Platform: Mac OS
I got the same issue, hope this to be fixed soon.

@achimnol
Copy link
Contributor

achimnol commented Mar 21, 2018

Cython 0.28 and 0.28.1 which includes the required patch is released now. 🎉
Ref: The Cython 0.28.1 changelog
@1st1 I think it is the time to update uvloop! 😉

1st1 added a commit that referenced this issue May 22, 2018
Use new @cython.iterable_coroutine instead of patching the
generated C code.

Fixes issue #122.
@1st1
Copy link
Member

1st1 commented May 23, 2018

Fixed in master. Please test :)

@1st1 1st1 closed this as completed May 23, 2018
@newskooler
Copy link

I keep having this issue. I am using the latest cpython and uvloop. Any clues how I can fix this? : )

@1st1
Copy link
Member

1st1 commented Jul 1, 2020

Not sure. Most likely it's unrelated to uvloop. I suggest debugging the line that causes this exception.

@wiedehopf
Copy link

In case someone else gets this error message, just convert to async def / await ... that fixed the issue for me.
It's usually as simple as replacing like this:

@asyncio.coroutine
def somefunction:
    reader, writer = yield from asyncio.open_connection(self.host, self.port)
    yield from asyncio.sleep(60.0)

async def asdfasdf:
    reader, writer = await asyncio.open_connection(self.host, self.port)
    await asyncio.sleep(60.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests