<p>I'm trying to watch the kubernetes resource like pods with kubernetes python client(version 9.0), but the method of watch.stream() seems to be suspended when i watch the k8s resource after few minutes later</p>

<pre class="lang-py prettyprint-override"><code>v1 = client.CoreV1Api()
w = watch.Watch()
for resource in w.stream(v1.list_namespaced_pod):
    dosomething(resource)

</code></pre>

<p>how do i always keep watching the kebernetes pod</p>

<p>You are hitting probably this <a href="https://github.com/kubernetes-client/python/issues/728" rel="nofollow noreferrer">issue</a>, and as workaround mentioned in this <a href="https://github.com/kubernetes-client/python/issues/728#issuecomment-455279700" rel="nofollow noreferrer">comment</a> you can try like below:</p>

<pre><code>from kubernetes import client, config, watch
from urllib3.exceptions import ProtocolError
config.load_kube_config()
api_instance = client.CoreV1Api()
while True:
  w = watch.Watch()
  try:
    for event in w.stream(api_instance.list_namespaced_pod, namespace="default"):
      print("Event: %s %s %s" % (event['type'],event['object'].kind, event['object'].metadata.name))
  except ProtocolError:
    print("watchPodEvents ProtocolError, continuing..")
</code></pre>

<p>Hope it helps!</p>
