-
I have web server on aiohttp and DB on aiobotocore('dynamodb'). As I understand aiobotocore client should only be used inside with statement. How do I then integrate it into aiohttp? My current solution: async def on_startup(app):
session = aiobotocore.session.get_session()
manager = session.create_client('dynamodb')
client = await manager.__aenter__()
app['manager'] = manager
app['client'] = client
async def on_shutdown(app):
await app['manager'].__aexit__(
exc_type=None,
exc_val=None,
exc_tb=None
)
web.run_app(
on_startup=on_startup,
on_shutdown=on_shutdown,
) Is it an intended solution? I do not like direct calls to |
Beta Was this translation helpful? Give feedback.
Answered by
thehesiod
Jul 18, 2022
Replies: 1 comment 3 replies
-
can use AsyncExitStack to abstract things from contextlib import AsyncExitStack
exit_stack = app['exit_stack'] = AsyncExitStack()
app['client'] = await exit_stack.enter_async_context(session.create_client('dynamodb'))
...
await app['exit_stack'].__aexit__(...) really would be nice if aiohttp provided an exit stack we could chain to. |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
kuk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can use AsyncExitStack to abstract things
really would be nice if aiohttp provided an exit stack we could chain to.