asyncpg
asyncpg copied to clipboard
notice callback not awaited
- asyncpg version: 0.23.0
- Python version: 3.9.2
- Platform: Linux
- Do you use pgbouncer?: no
- Did you install asyncpg with pip?: yes
- Can the issue be reproduced under both asyncio and uvloop?: only experienced it once, without uvloop
/root/.local/lib/python3.9/site-packages/asyncpg/connection.py:1435: RuntimeWarning: coroutine 'vacuum_job.<locals>.async_notice_callb' was never awaited
cb(con_ref, message)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
import asyncio
import asyncpg
async def vacuum_job():
conn = await asyncpg.connect(
user='user', password='password', database='database', host='host')
# Execute some queries or tasks
await conn.execute('VACUUM FULL')
await conn.close()
async def async_notice_callback(con, message):
# Handle notices asynchronously here
pass
async def main():
conn = await asyncpg.connect(
user='user', password='password', database='database', host='host',
command_timeout=60, # Adjust the timeout as needed
notice_callback=async_notice_callback # Optional, if you need a notice callback
)
# Create a task for the vacuum job
vacuum_task = asyncio.create_task(vacuum_job())
try:
# Execute some queries or tasks on the main connection
result = await conn.fetch('SELECT * FROM some_table')
print(result)
except asyncio.CancelledError:
# Handle the task cancellation if needed
pass
finally:
await conn.close()
await vacuum_task # Wait for the vacuum job to complete
if __name__ == "__main__":
asyncio.run(main())