File tree Expand file tree Collapse file tree 2 files changed +6
-3
lines changed
src/crawlee/crawlers/_basic
tests/unit/crawlers/_basic Expand file tree Collapse file tree 2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -690,7 +690,6 @@ def sigint_handler() -> None:
690690 except CancelledError :
691691 pass
692692 finally :
693- await self ._crawler_state_rec_task .stop ()
694693 if threading .current_thread () is threading .main_thread ():
695694 with suppress (NotImplementedError ):
696695 asyncio .get_running_loop ().remove_signal_handler (signal .SIGINT )
@@ -742,7 +741,10 @@ async def _run_crawler(self) -> None:
742741 await exit_stack .enter_async_context (context ) # type: ignore[arg-type]
743742
744743 self ._crawler_state_rec_task .start ()
745- await self ._autoscaled_pool .run ()
744+ try :
745+ await self ._autoscaled_pool .run ()
746+ finally :
747+ await self ._crawler_state_rec_task .stop ()
746748
747749 # Emit PERSIST_STATE event when crawler is finishing to allow listeners to persist their state if needed
748750 if not self .statistics .state .crawler_last_started_at :
Original file line number Diff line number Diff line change 55import concurrent
66import json
77import logging
8+ import multiprocessing
89import os
910import sys
1011import time
@@ -1678,7 +1679,7 @@ async def test_crawler_statistics_persistence(tmp_path: Path) -> None:
16781679
16791680 This test simulates starting the crawler process twice, and checks that the statistics include first run."""
16801681
1681- with concurrent .futures .ProcessPoolExecutor () as executor :
1682+ with concurrent .futures .ProcessPoolExecutor (mp_context = multiprocessing . get_context ( 'fork' ) ) as executor :
16821683 # Crawl 2 requests in the first run and automatically persist the state.
16831684 first_run_state = executor .submit (
16841685 _process_run_crawler ,
You can’t perform that action at this time.
0 commit comments