|
3 | 3 |
|
4 | 4 | from aiohttp import ClientSession |
5 | 5 |
|
6 | | -# Singleton aiohttp.ClientSession instance. |
7 | | -CLIENT_SESSION: ClientSession |
8 | 6 |
|
| 7 | +class Session: |
| 8 | + # Singleton aiohttp.ClientSession instance. |
| 9 | + CLIENT_SESSION: ClientSession |
| 10 | + LOGGER = logging.getLogger(__name__) |
9 | 11 |
|
10 | | -LOGGER = logging.getLogger(__name__) |
| 12 | + async def setup_client_session(self): |
| 13 | + """Set up the application-global aiohttp.ClientSession instance. |
11 | 14 |
|
| 15 | + aiohttp recommends that only one ClientSession exist for the lifetime of an application. |
| 16 | + See: https://docs.aiohttp.org/en/stable/client_quickstart.html#make-a-request |
12 | 17 |
|
13 | | -async def setup_client_session(): |
14 | | - """Set up the application-global aiohttp.ClientSession instance. |
| 18 | + """ |
| 19 | + global CLIENT_SESSION # pylint: disable=global-statement |
| 20 | + self.LOGGER.info("Setting up global aiohttp.ClientSession.") |
| 21 | + CLIENT_SESSION = ClientSession() |
15 | 22 |
|
16 | | - aiohttp recommends that only one ClientSession exist for the lifetime of an application. |
17 | | - See: https://docs.aiohttp.org/en/stable/client_quickstart.html#make-a-request |
18 | | -
|
19 | | - """ |
20 | | - global CLIENT_SESSION # pylint: disable=global-statement |
21 | | - LOGGER.info("Setting up global aiohttp.ClientSession.") |
22 | | - CLIENT_SESSION = ClientSession() |
23 | | - |
24 | | - |
25 | | -async def teardown_client_session(): |
26 | | - """Close the application-global aiohttp.ClientSession. |
27 | | - """ |
28 | | - global CLIENT_SESSION # pylint: disable=global-statement |
29 | | - LOGGER.info("Closing global aiohttp.ClientSession.") |
30 | | - await CLIENT_SESSION.close() |
| 23 | + async def teardown_client_session(self): |
| 24 | + """Close the application-global aiohttp.ClientSession. |
| 25 | + """ |
| 26 | + global CLIENT_SESSION # pylint: disable=global-statement |
| 27 | + self.LOGGER.info("Closing global aiohttp.ClientSession.") |
| 28 | + await CLIENT_SESSION.close() |
0 commit comments