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

Failed on test example #686

Closed
redradist opened this issue May 30, 2020 · 3 comments
Closed

Failed on test example #686

redradist opened this issue May 30, 2020 · 3 comments

Comments

@redradist
Copy link

redradist commented May 30, 2020

Hi all,

I have tried to run the following code:

import asyncio
from aiopg.sa import create_engine
import sqlalchemy as sa

metadata = sa.MetaData()

tbl = sa.Table('tbl', metadata,
    sa.Column('id', sa.Integer, primary_key=True),
    sa.Column('val', sa.String(255)))

async def create_table(engine):
    async with engine.acquire() as conn:
        await conn.execute('DROP TABLE IF EXISTS tbl')
        await conn.execute('''CREATE TABLE tbl (
                                  id serial PRIMARY KEY,
                                  val varchar(255))''')

async def go():
    async with create_engine(user='postgres',
                             database='aiopg',
                             host='127.0.0.1',
                             password='postgres') as engine:

        async with engine.acquire() as conn:
            await conn.execute(tbl.insert().values(val='abc'))

            async for row in conn.execute(tbl.select()):
                print(row.id, row.val)

loop = asyncio.get_event_loop()
loop.run_until_complete(go())

And get the following error:

Traceback (most recent call last):
  File "my_script.py", line 109, in <module>
    loop.run_until_complete(go())
  File "C:\Python\Python3\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File "my_script.py", line 97, in go
    async with create_engine(user='postgres',
  File "C:\Python\Python3\lib\site-packages\aiopg\utils.py", line 94, in __aenter__
    self._obj = await self._coro
  File "C:\Python\Python3\lib\site-packages\aiopg\sa\engine.py", line 69, in _create_engine
    pool = await aiopg.create_pool(
  File "C:\Python\Python3\lib\site-packages\aiopg\pool.py", line 155, in from_pool_fill
    await self._fill_free_pool(False)
  File "C:\Python\Python3\lib\site-packages\aiopg\pool.py", line 193, in _fill_free_pool
    conn = await connect(
  File "C:\Python\Python3\lib\site-packages\aiopg\connection.py", line 38, in connect
    coro = Connection(
  File "C:\Python\Python3\lib\site-packages\aiopg\connection.py", line 92, in __init__
    self._loop.add_reader(self._fileno, self._ready, self._weakref)
  File "C:\Python\Python3\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError
Exception ignored in: <function Connection.__del__ at 0x03DD7DF0>
Traceback (most recent call last):
  File "C:\Python\Python3\lib\site-packages\aiopg\connection.py", line 512, in __del__
  File "C:\Python\Python3\lib\site-packages\aiopg\connection.py", line 310, in close
  File "C:\Python\Python3\lib\site-packages\aiopg\connection.py", line 285, in _close
  File "C:\Python\Python3\lib\asyncio\events.py", line 504, in remove_reader
NotImplementedError: 

Process finished with exit code 1

I think it is due to invalid port, but I have not found how to set port number ...
I tried:

...
    async with create_engine(user='postgres',
                             database='aiopg',
                             host='127.0.0.1',
                             port=<number>,
                             password='postgres') as engine:
...

But it did not helped (

@redradist
Copy link
Author

I have fixed it on Windows with the following event_loop_policy:

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

But I still did not get why this happens on Windows (

@Pliner Pliner closed this as completed Mar 21, 2021
@Pliner
Copy link
Member

Pliner commented Mar 21, 2021

Duplicate of #678

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

2 participants