Skip to content

Problem with create_pool example from API #74

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

Closed
johannspies opened this issue Feb 2, 2017 · 4 comments
Closed

Problem with create_pool example from API #74

johannspies opened this issue Feb 2, 2017 · 4 comments

Comments

@johannspies
Copy link

johannspies commented Feb 2, 2017

  • asyncpg version:
    python3-asyncpg 0.8.4-1 amd64
  • PostgreSQL version:
    postgresql-9.6 9.6.1-2 amd64
  • Python version:
    python3-ipython 5.1.0-3
    python3 3.5.3-1 amd64
  • Platform:
    Linux 4.8.0-2-amd64 Other examples? #1 SMP Debian 4.8.15-2 (2017-01-04) x86_64 GNU/Linux (Debian testing/sid)
  • Do you use pgbouncer?: No
  • Do you use the wheel package or built locally
    (if locally, which version of Cython was used)?
    : No
  • Can you the issue be reproduced when running under
    uvloop?
    :
    I do not know.

Examples from the API causes syntax errors:

pool = await asyncpg.create_pool(user='postgres', command_timeout=60)
File "", line 1
pool = await asyncpg.create_pool(user='postgres', command_timeout=60)
^
SyntaxError: invalid syntax

and (in jupyter notebook)

async with asyncpg.create_pool(user='postgres',
command_timeout=60) as pool:
async with pool.acquire() as con:
await con.fetch('SELECT 1')

File "", line 1
async with asyncpg.create_pool(user='postgres',
^
SyntaxError: invalid syntax

While I can do other stuff like this without a problem:

async def xmlrecord(db,schema,tb):
"""Get one xml record from wos_source.cover_2016"""
conn = await asyncpg.connect(database=db,
user='xxxxxx',
password='xxxxxx',
host='localhost')
x = """
SELECT ut, xml from {}.{} where processed is not true limit 1;
""".format(schema, tb)
stmt = await conn.prepare(x)
result = await stmt.fetch()
ut = result[0]['ut']
xml = result[0]['xml']
return ut,xml

@elprans
Copy link
Member

elprans commented Feb 2, 2017

You cannot use await outside of an async def function. The doc example is an excerpt. We'll tweak it for clarity.

@johannspies
Copy link
Author

johannspies commented Feb 6, 2017 via email

@johannspies
Copy link
Author

johannspies commented Feb 6, 2017 via email

@elprans
Copy link
Member

elprans commented Feb 7, 2017

@johannspies We have no mailing list dedicated to asyncpg currently. It would probably be best to ask for help and guidance on usage on Stack Overflow.

@elprans elprans closed this as completed Feb 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants