Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit ee58269

Browse files
author
Chen Li
committed
Add flag to enable keep the watch action working all the time
Fixes issue: kubernetes-client/python#124
1 parent a41c447 commit ee58269

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

watch/watch.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,14 @@ def unmarshal_event(self, data, return_type):
8383
js['object'] = self._api_client.deserialize(obj, return_type)
8484
return js
8585

86-
def stream(self, func, *args, **kwargs):
86+
def stream(self, func, keep = False, *args, **kwargs):
8787
"""Watch an API resource and stream the result back via a generator.
8888
8989
:param func: The API function pointer. Any parameter to the function
9090
can be passed after this parameter.
9191
92+
:param keep: Flag to keep the watch work all the time.
93+
9294
:return: Event object with these keys:
9395
'type': The type of event such as "ADDED", "DELETED", etc.
9496
'raw_object': a dict representing the watched object.
@@ -113,12 +115,17 @@ def stream(self, func, *args, **kwargs):
113115
return_type = self.get_return_type(func)
114116
kwargs['watch'] = True
115117
kwargs['_preload_content'] = False
116-
resp = func(*args, **kwargs)
117-
try:
118-
for line in iter_resp_lines(resp):
119-
yield self.unmarshal_event(line, return_type)
120-
if self._stop:
121-
break
122-
finally:
123-
resp.close()
124-
resp.release_conn()
118+
119+
while True:
120+
resp = func(*args, **kwargs)
121+
try:
122+
for line in iter_resp_lines(resp):
123+
yield self.unmarshal_event(line, return_type)
124+
if self._stop:
125+
break
126+
finally:
127+
resp.close()
128+
resp.release_conn()
129+
130+
if not keep:
131+
break

0 commit comments

Comments
 (0)