MCPcopy Index your code
hub / github.com/kubernetes-client/python / stream_logs

Function stream_logs

examples/pod_logs_non_blocking.py:17–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15
16
17def 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
44t = threading.Thread(target=stream_logs)

Callers

nothing calls this directly

Calls 2

closeMethod · 0.45

Tested by

no test coverage detected