File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff 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" ]
You can’t perform that action at this time.
0 commit comments