Async/Await unclosed connector
See original GitHub issueI’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
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
aiohttp: Unclosed client session client_session - Stack Overflow
I have a test.py file and a AsyncioCurl.py file. I already use ...
Read more >Unclosed connector / client session when using asyncio #13242
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external ...
Read more >Using Asyncio with Elasticsearch
Receiving 'Unclosed client session / connector' warning?¶. This warning is created by aiohttp when an open HTTP connection is garbage collected. You'll ...
Read more >Asyncpraw/aiohttp issue : r/redditdev
I get these "Unclosed client session" and "Unclosed connector" messages, which lead into: Traceback (most recent call last): File "D:\Code ...
Read more >Why do I keep getting this message: "Unclosed client session"?
I am trying to encode a live event using async functions for python and my program looks somewhat like: client = AzureMediaServices(credentials, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for your help. I’ll try to figure it out on my side.
We’ll check why there may be a leak there, and also if we can implement
async with
. Thanks for reporting.