-
Notifications
You must be signed in to change notification settings - Fork 115
Closed
Description
I'm using async call inside class Map method _get_city_center_coord.
import ipinfo
import folium
class Map:
def __init__(self, event_coordinate=None, zoom_start=15, popup=None, tooltip=None):
self.event_coordinate = event_coordinate
self.zoom_start = zoom_start
self.popup = popup
self.tooltip = tooltip
@staticmethod
async def _get_city_center_coord():
handler = ipinfo.getHandlerAsync('ipinfo_access_token')
details = await handler.getDetails()
lat, lon = (details.latitude, details.longitude)
return lat, lon
async def show_events(self, event_list):
m = await self._init_map()
for event in event_list:
id, popup, lat, long, tooltip = event
folium.Marker(
location=list((lat, long)),
popup=popup,
tooltip=tooltip,
icon=folium.Icon(color="red", icon="info-sign")
).add_to(m)
return m
async def _init_map(self):
if self.event_coordinate:
return folium.Map(location=self.event_coordinate, zoom_start=self.zoom_start)
else:
return folium.Map(
location=await self._get_city_center_coord(),
zoom_start=self.zoom_start
)
And this code used by fastapi framework this way
@router.get('/all', response_model=List[EventList])
async def events_list(
request: Request,
service: EventsService = Depends(),
user: User = Depends(UserService.get_authenticated_user_id),
):
events = await service.get_list()
events_data = [
(
event['id'], event['title'], event['location']['lat'],
event['location']['long'], event['activity']['name']
)
for event in events
]
m = await Map(zoom_start=12).show_events(events_data)
return templates.TemplateResponse(
'events.html',
context={
'request': request,
'events': events,
'm': m._repr_html_(),
'user': user
}
)
Everything works fine, IP coordinates are detected and the map is displayed. But in the console I see a warning
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f25f9e1e800>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f25f9e2bac0>, 178355.411)]']
connector: <aiohttp.connector.TCPConnector object at 0x7f25f9e1dff0>
Is there a way to close the connection after a request has been made? It looks like there is a lack of async with syntax implementation
Metadata
Metadata
Assignees
Labels
No labels