Closed RichardBruskiewich closed 3 years ago
Sqlite?
Hi @kbruskiewicz sorry about the confusion. The ClientSession purely relates to the AIOHTTP internet session (session class).
The basic form is:
async with aiohttp.ClientSession() as session:
async with session.get('http://httpbin.org/get') as resp:
print(resp.status)
print(await resp.text())
but in the above article link, it is suggested that the ClientSession object be maintained globally in the application, not local to a given request. I just don't know where to put it while ensuring that it can be cleanly closed once the application shuts down.Namely:
session = aiohttp.ClientSession()
# Flask/connexion application running...
# periodically, with some URL access
async with session.get('...'):
# processing URL response here
# ...then the application running running some more...
# Application then shutting down so...
await session.close()
Resolved by get_global_session(cls)
method in the KgeaSession
class of the kgea.server.web_services.kgea_session
module.
We use AIOHTTP to facilate async access to files across the web. Best practices suggest that the AIOHTTP client session should be managed as a singleton (not done this way as the moment). See https://docs.aiohttp.org/en/stable/client_quickstart.html#make-a-request.
Unsure how to robustly integrate the session lifecycle globally into the Python Flask/Connexion application.