Skip to content

Commit 1025287

Browse files
author
Konstantin
committed
Merge remote-tracking branch 'origin/fix-it' into fix-it
2 parents 7245761 + 519d7e7 commit 1025287

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/edi_energy_scraper/scraper.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ def __init__(
4343
self._session = aiohttp.ClientSession(connector=self.tcp_connector)
4444
self._timeout = ClientTimeout(total=30.0)
4545

46+
async def close(self) -> None:
47+
"""Properly closes the aiohttp session."""
48+
if self._session and not self._session.closed:
49+
await self._session.close()
50+
if not self.tcp_connector.closed:
51+
await self.tcp_connector.close()
52+
4653
async def get_documents_overview(self) -> list[Document]:
4754
"""
4855
download meta information about all available documents
@@ -163,5 +170,10 @@ async def get_best_match(
163170
downloaded_path.rename(path)
164171
return path
165172

173+
def __del__(self) -> None:
174+
"""Ensure cleanup when the instance is destroyed."""
175+
if not self._session.closed:
176+
asyncio.create_task(self.close())
177+
166178

167179
__all__ = ["EdiEnergyScraper"]

0 commit comments

Comments
 (0)