Hi,
I am trying to find a better way to handle of using session.
if i change the code to assign
Is the code change is inline with best practice with handling session ?
Original code :
@app.route('/lookupApplication')
async def lookup_id(request):
async with aiohttp.ClientSession() as session:
async with session.get(<URL>) as resp:
resp_data = await resp.json()
if __name__ == '__main__':
app.run(debug=True, access_log=True, before_start=init,)
Updated code :
@stare.listener('before_server_start')
async def initialize(app, loop):
app.ctx.httpSession = aiohttp.ClientSession()
@app.route('/lookupApplication')
async def lookup_id(request):
async with app.ctx.httpSession.get(<URL>) as resp:
resp_data = await resp.json()
if __name__ == '__main__':
app.run(debug=True, access_log=True, before_start=init,)