()
| 15 | |
| 16 | |
| 17 | def stream_logs(): |
| 18 | config.load_kube_config() |
| 19 | v1 = client.CoreV1Api() |
| 20 | |
| 21 | resp = v1.read_namespaced_pod_log( |
| 22 | name="log-demo", |
| 23 | namespace="default", |
| 24 | follow=True, |
| 25 | _preload_content=False |
| 26 | ) |
| 27 | |
| 28 | # 👇 make socket non-blocking with timeout |
| 29 | resp._fp.fp.raw._sock.settimeout(1) |
| 30 | |
| 31 | try: |
| 32 | while not stop_event.is_set(): |
| 33 | try: |
| 34 | data = resp.read(1024) |
| 35 | if data: |
| 36 | print(data.decode(), end="") |
| 37 | except (socket.timeout, ReadTimeoutError): |
| 38 | continue |
| 39 | finally: |
| 40 | resp.close() |
| 41 | print("\nLog streaming stopped cleanly.") |
| 42 | |
| 43 | |
| 44 | t = threading.Thread(target=stream_logs) |
nothing calls this directly
no test coverage detected