| 51 | self._thread: threading.Thread | None = None |
| 52 | |
| 53 | def loop(self) -> asyncio.AbstractEventLoop: |
| 54 | with self._lock: |
| 55 | if self._loop is None or self._thread is None or not self._thread.is_alive(): |
| 56 | self._loop = asyncio.new_event_loop() |
| 57 | self._thread = threading.Thread( |
| 58 | target=self._loop.run_forever, |
| 59 | name="litellm-harness-loop", |
| 60 | daemon=True, |
| 61 | ) |
| 62 | self._thread.start() |
| 63 | return self._loop |
| 64 | |
| 65 | def submit(self, coro: Coroutine[object, None, T]) -> Future[T]: |
| 66 | return asyncio.run_coroutine_threadsafe(coro, self.loop()) |