-
Notifications
You must be signed in to change notification settings - Fork 424
Closed
Description
- asyncpg version: asyncpg==0.12.0
- PostgreSQL version: PostgreSQL 9.6.3 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit
- Python version: 3.6.2
- Platform:
macOS Sierra 10.12.6 (16G29)
: Platform <<<<<=====--------- - Do you use pgbouncer?: No
- Did you install asyncpg with pip?: Yes
- If you built asyncpg locally, which version of Cython did you use?:
- Can the issue be reproduced under both asyncio and
uvloop?: Yes
Hello!
I'm trying to make connection pool with loop.run_until_complete()
but it return GatheringFuture
instance.
Also tried:
- run this code on Ubuntu linux works correctly
- make pool with context manager (
async with asyncpg.create_pool(...)
) works correctly
What am I doing wrong?
I'm know this is not a big problem, because macOS is not a production platform. But it would be great to find the reason.
The Code
In [1]: import asyncio, asyncpg
In [2]: loop = asyncio.get_event_loop()
In [3]: pool_defer = asyncpg.create_pool(dsn='postgres://avt:123@localhost:55432/avt', loop=loop)
In [4]: loop.run_until_complete(pool_defer)
Out[4]: <_GatheringFuture finished result=[None, None, None, None, None, None, ...]>
Extended example
#!/usr/bin/env python3
# coding=utf-8
import asyncio
import unittest
import asyncpg
import asyncpg.pool
dsn = f'postgres://avt:123@localhost:55432/avt' # your postgres DSN here
class TestMakePool(unittest.TestCase):
def setUp(self):
super().setUp()
self.loop = asyncio.new_event_loop()
def tearDown(self):
self.loop.close()
super().tearDown()
def test_make_pool(self):
pool_defer = asyncpg.create_pool(dsn,loop=self.loop)
pool = self.loop.run_until_complete(pool_defer)
self.assertIsInstance(pool, asyncio.Future)
self.assertIsInstance(pool, asyncpg.pool.Pool) # failed here
con = self.loop.run_until_complete(pool.acquire())
try:
res = self.loop.run_until_complete(con.fetchval('SELECT 1+1'))
finally:
self.loop.run_until_complete(pool.release(con))
self.loop.run_until_complete(pool.close())
self.assertEqual(2, res)
def test_make_pool_context_manager(self):
res = self.loop.run_until_complete(self._make_pool_cm())
self.assertEqual(2, res)
async def _make_pool_cm(self):
res = None
async with asyncpg.create_pool(dsn, loop=self.loop) as pool:
self.assertIsInstance(pool, asyncpg.pool.Pool)
async with pool.acquire() as con:
res = await con.fetchval('SELECT 1+1')
return res
if __name__ == '__main__':
unittest.main()
Metadata
Metadata
Assignees
Labels
No labels