mirror of https://github.com/scrapy/scrapy.git
Solve issue making CI hang?
This commit is contained in:
parent
2b397afe52
commit
44f0fd0d37
|
|
@ -278,6 +278,11 @@ class Crawler:
|
|||
if self.engine is None:
|
||||
return
|
||||
|
||||
# During shutdown callbacks, graceful stop may be re-entered after
|
||||
# the engine has already switched to non-running state.
|
||||
if mode == "graceful" and not self.engine.running:
|
||||
return
|
||||
|
||||
try:
|
||||
await self.engine.stop_async(mode=mode)
|
||||
except RuntimeError as exc:
|
||||
|
|
|
|||
|
|
@ -797,6 +797,26 @@ async def test_crawler_stop_async_invalid_mode() -> None:
|
|||
await crawler.stop_async(mode="invalid") # type: ignore[arg-type]
|
||||
|
||||
|
||||
@coroutine_test
|
||||
async def test_crawler_graceful_stop_non_running_engine_is_noop() -> None:
|
||||
crawler = get_crawler(DefaultSpider)
|
||||
crawler.crawling = True
|
||||
|
||||
class DummyEngine:
|
||||
running = False
|
||||
called = False
|
||||
|
||||
async def stop_async(self, *, mode: str = "graceful") -> None:
|
||||
self.called = True
|
||||
|
||||
dummy_engine = DummyEngine()
|
||||
crawler.engine = dummy_engine # type: ignore[assignment]
|
||||
|
||||
await crawler.stop_async(mode="graceful")
|
||||
|
||||
assert dummy_engine.called is False
|
||||
|
||||
|
||||
@coroutine_test
|
||||
async def test_crawler_force_stop_falls_back_to_fast(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
|
|
|
|||
Loading…
Reference in New Issue