Gracefully stop the execution engine. .. versionadded:: 2.14
(self)
| 211 | return deferred_from_coro(self.stop_async()) |
| 212 | |
| 213 | async def stop_async(self) -> None: |
| 214 | """Gracefully stop the execution engine. |
| 215 | |
| 216 | .. versionadded:: 2.14 |
| 217 | """ |
| 218 | |
| 219 | if not self._starting: |
| 220 | raise RuntimeError("Engine not running") |
| 221 | |
| 222 | self.running = self._starting = False |
| 223 | self._stopping = True |
| 224 | if self._start_request_processing_awaitable is not None: |
| 225 | if ( |
| 226 | not is_asyncio_available() |
| 227 | or self._start_request_processing_awaitable |
| 228 | is not asyncio.current_task() |
| 229 | ): |
| 230 | # If using the asyncio loop and stop_async() was called from |
| 231 | # start() itself, we can't cancel it, and _start_request_processing() |
| 232 | # will exit via the self.running check. |
| 233 | self._start_request_processing_awaitable.cancel() |
| 234 | self._start_request_processing_awaitable = None |
| 235 | if self.spider is not None: |
| 236 | await self.close_spider_async(reason="shutdown") |
| 237 | await self.signals.send_catch_log_async(signal=signals.engine_stopped) |
| 238 | if self._closewait: |
| 239 | self._closewait.callback(None) |
| 240 | |
| 241 | def close(self) -> Deferred[None]: # pragma: no cover |
| 242 | warnings.warn( |