How can I avoid duplication of code? #6793
Replies: 1 comment
-
I don't know what your core application/framework looks like, but if you were building an aiohttp (server) application, you could just put it in a cleanup context like:
I'm sure you could do something similar to ensure it gets cleaned up when your application shuts down. Also, you don't need to use |
Beta Was this translation helpful? Give feedback.
-
async with aiohttp.ClientSession() as session:
is duplicated every time I want to make an http request with aiohttpSo I have the following code, and I am going to be making multiple get requests using this aiohttp. How can I avoid having to copy and paste this multiple times throughout my code? I cannot cache it with a memoize decorator. I cannot cache it because it's
async
, so how do I cache aClientSession
? I would like to have oneClientSession
object that is used everywhere throughout my code.Beta Was this translation helpful? Give feedback.
All reactions