Since commit 1bf70e6c3a53 ("tools/net/ynl: improve async notification
handling"), check_ntf() would block indefinitely if there's no messages.
In some cases we want to set a limit on waiting time. This patch adds
max_reties parameter check_ntf(), and makes it stop when no message is
recievied in that number of consecutive retries.
Signed-off-by: Xiao Liang <redacted>
---
tools/net/ynl/lib/ynl.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 92f85698c50e..dff5166a4650 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -907,7 +907,8 @@ class YnlFamily(SpecFamily):
msg['msg'] = attrs
self.async_msg_queue.put(msg)
- def check_ntf(self, interval=0.1):
+ def check_ntf(self, interval=0.1, max_retries=None):
+ retry = 0
while True:
try:
reply = self.sock.recv(self._recv_size, socket.MSG_DONTWAIT)@@ -933,7 +934,11 @@ class YnlFamily(SpecFamily):
try:
yield self.async_msg_queue.get_nowait()
+ retry = 0
except queue.Empty:
+ retry += 1
+ if max_retries is not None and retry > max_retries:
+ return
try:
time.sleep(interval)
except KeyboardInterrupt:--
2.47.0