等待后台线程退出,通常配合 cancel() 使用以保证任务完整收尾。
(self, timeout: Optional[float] = None)
| 83 | self._stop_event.set() |
| 84 | |
| 85 | def join(self, timeout: Optional[float] = None) -> None: |
| 86 | """ |
| 87 | 等待后台线程退出,通常配合 cancel() 使用以保证任务完整收尾。 |
| 88 | """ |
| 89 | with self._lock: |
| 90 | thread = self._thread |
| 91 | |
| 92 | if thread is not None and thread.is_alive(): |
| 93 | thread.join(timeout) |
| 94 | |
| 95 | @property |
| 96 | def execution_count(self) -> int: |