python icon indicating copy to clipboard operation
python copied to clipboard

How to perform non-blocking reads using `read_namespaced_pod_log`

Open emike922 opened this issue 1 month ago • 2 comments

I am trying to set up a background thread that follows the log stream of a container and performs some actions on each record. The thread shall have a means to gracefully terminate it from the main thread, e.g. using threading.Event.

I have tried various combinations of read_namespaced_pod_log with follow=True. Iterating over read_namespaced_pod_log(...).stream(), iterating over Watch().stream(), passing _preload_content=False and such. But it always comes down to this: The for loop / next() / iter_resp_lines() call eventually blocks once we are all caught up with the container's logs, and setting the Event during this time will not terminate the thread until the next log event occurs.

Could you please provide an example on how to do non-blocking reads with read_namespaced_pod_log?

emike922 avatar Nov 30 '25 08:11 emike922

Could you check if https://github.com/tomplus/kubernetes_asyncio would help?

/help

roycaihw avatar Dec 04 '25 21:12 roycaihw

@roycaihw: This request has been marked as needing help from a contributor.

Guidelines

Please ensure that the issue body includes answers to the following questions:

  • Why are we solving this issue?
  • To address this issue, are there any code changes? If there are code changes, what needs to be done in the code and what places can the assignee treat as reference points?
  • How can the assignee reach out to you for help?

For more details on the requirements of such an issue, please see here and ensure that they are met.

If this request no longer meets these requirements, the label can be removed by commenting with the /remove-help command.

In response to this:

Could you check if https://github.com/tomplus/kubernetes_asyncio would help?

/help

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

k8s-ci-robot avatar Dec 04 '25 21:12 k8s-ci-robot