perf(session): improve page management and speed up execution

Close pages immediately after tasks finish to reduce resource usage and
improve overall performance. Update corresponding test files to reflect
the new page lifecycle management.
This commit is contained in:
Abdullah
2025-09-17 18:49:45 +03:00
parent 6b2675c7dd
commit 7ba333c3c9
7 changed files with 27 additions and 83 deletions
+6 -5
View File
@@ -305,8 +305,9 @@ class DynamicSession(DynamicSessionMixin, SyncSession):
page_info.page, first_response, final_response, params.selector_config
)
# Mark the page as finished for next use
page_info.mark_finished()
# Close the page, to free up resources
page_info.page.close()
self.page_pool.pages.remove(page_info)
return response
@@ -554,9 +555,9 @@ class AsyncDynamicSession(DynamicSessionMixin, AsyncSession):
page_info.page, first_response, final_response, params.selector_config
)
# Mark the page as finished for next use
page_info.mark_finished()
# Close the page, to free up resources
await page_info.page.close()
self.page_pool.pages.remove(page_info)
return response
except Exception as e: # pragma: no cover