forked from ExpDev07/coronavirus-tracker-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttputils.py
More file actions
30 lines (20 loc) · 900 Bytes
/
httputils.py
File metadata and controls
30 lines (20 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""app.utils.httputils.py"""
import logging
from aiohttp import ClientSession
# Singleton aiohttp.ClientSession instance.
CLIENT_SESSION: ClientSession
LOGGER = logging.getLogger(__name__)
async def setup_client_session():
"""Set up the application-global aiohttp.ClientSession instance.
aiohttp recommends that only one ClientSession exist for the lifetime of an application.
See: https://docs.aiohttp.org/en/stable/client_quickstart.html#make-a-request
"""
global CLIENT_SESSION # pylint: disable=global-statement
LOGGER.info("Setting up global aiohttp.ClientSession.")
CLIENT_SESSION = ClientSession()
async def teardown_client_session():
"""Close the application-global aiohttp.ClientSession.
"""
global CLIENT_SESSION # pylint: disable=global-statement
LOGGER.info("Closing global aiohttp.ClientSession.")
await CLIENT_SESSION.close()