Skip to content

🕷️ The BEST Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev

fix(Adaptor): Add cleanup function to handle possible memory leak

Karim shoairffde7e8ad99b
diff --git a/scrapling/parser.py b/scrapling/parser.py
index 9387711..3aed83b 100644
--- a/scrapling/parser.py
+++ b/scrapling/parser.py
@@ -181,6 +181,14 @@ class Adaptor(SelectorsGeneration):
else {}
)
+ def __del__(self):
+ """Ensure cleanup happens"""
+ if hasattr(self, "_storage") and self._storage:
+ try:
+ self._storage.close()
+ finally:
+ self._storage = None
+
# Node functionalities, I wanted to move to a separate Mixin class, but it had a slight impact on performance
@staticmethod
def _is_text_node(