Stop the background worker task. Args: close_queue: Whether to close the queue resources. Set to False when multiple workers share the same queue.
(self, close_queue: bool = True)
| 348 | logger.info("Queue worker task%s started successfully", partition_info) |
| 349 | |
| 350 | async def stop(self, close_queue: bool = True) -> None: |
| 351 | """ |
| 352 | Stop the background worker task. |
| 353 | |
| 354 | Args: |
| 355 | close_queue: Whether to close the queue resources. Set to False |
| 356 | when multiple workers share the same queue. |
| 357 | """ |
| 358 | if not self._running: |
| 359 | return |
| 360 | |
| 361 | self._running = False |
| 362 | |
| 363 | if self._task: |
| 364 | self._task.cancel() |
| 365 | try: |
| 366 | await self._task |
| 367 | except asyncio.CancelledError: |
| 368 | pass |
| 369 | self._task = None |
| 370 | |
| 371 | if close_queue: |
| 372 | await self.queue.close() |