Код: Выделить всё
async def monitor(data_stream):
# ...
while True:
# ...
x, y = await data_stream.get_data()
await conn.execute("INSERT INTO table (x, y) VALUES ($1, $2)", x, y)
await asyncio.sleep(1)
async def main():
async with asyncpg.create_pool(user='user', password='pass', database='db', host='localhost') as pool:
# ...
await asyncio.gather(monitor(data_stream_1), monitor(data_stream_2), monitor(data_stream_3))
asyncio.run(main())
Из моего понимания пул соединений держит соединения открытыми, а пул. в теле петли.
Подробнее здесь: https://stackoverflow.com/questions/795 ... e-connecti