Yields log lines to a frontend until stop_event is set (if provided). This can be used in a Flask or FastAPI streaming endpoint.
(self, stop_event=None)
| 84 | self.subscribers.remove(q) |
| 85 | |
| 86 | def stream_to_frontend(self, stop_event=None): |
| 87 | """ |
| 88 | Yields log lines to a frontend until stop_event is set (if provided). |
| 89 | This can be used in a Flask or FastAPI streaming endpoint. |
| 90 | """ |
| 91 | q = self.subscribe() |
| 92 | try: |
| 93 | while True: |
| 94 | if stop_event and stop_event.is_set(): |
| 95 | break |
| 96 | try: |
| 97 | message = q.get(timeout=1) |
| 98 | yield message |
| 99 | except Empty: |
| 100 | continue |
| 101 | finally: |
| 102 | self.unsubscribe(q) |
nothing calls this directly
no test coverage detected