Skip to content

Commit ebc350d

Browse files
committed
Test Windows related issue
1 parent 3a28d42 commit ebc350d

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/crawlee/crawlers/_basic/_basic_crawler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff 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:

tests/unit/crawlers/_basic/test_basic_crawler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import concurrent
66
import json
77
import logging
8+
import multiprocessing
89
import os
910
import sys
1011
import 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,

0 commit comments

Comments
 (0)