* [PATCH net-next v1] tools: ynl: handle broken pipe gracefully in CLI
@ 2025-05-08 11:21 Donald Hunter
2025-05-08 13:47 ` Jakub Kicinski
2025-05-09 23:50 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Donald Hunter @ 2025-05-08 11:21 UTC (permalink / raw)
To: netdev, Jakub Kicinski, David S. Miller, Eric Dumazet,
Paolo Abeni, Simon Horman, Jan Stancek
Cc: donald.hunter, Donald Hunter
When sending YNL CLI output into a pipe, closing the pipe causes a
BrokenPipeError. E.g. running the following and quitting less:
./tools/net/ynl/pyynl/cli.py --family rt-link --dump getlink | less
Traceback (most recent call last):
File "/home/donaldh/net-next/./tools/net/ynl/pyynl/cli.py", line 160, in <module>
main()
~~~~^^
File "/home/donaldh/net-next/./tools/net/ynl/pyynl/cli.py", line 142, in main
output(reply)
~~~~~~^^^^^^^
File "/home/donaldh/net-next/./tools/net/ynl/pyynl/cli.py", line 97, in output
pprint.PrettyPrinter().pprint(msg)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
[...]
BrokenPipeError: [Errno 32] Broken pipe
Consolidate the try block for ops and notifications, and gracefully
handle the BrokenPipeError by adding an exception handler to the
consolidated try block.
Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
---
tools/net/ynl/pyynl/cli.py | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/tools/net/ynl/pyynl/cli.py b/tools/net/ynl/pyynl/cli.py
index 794e3c7dcc65..33ccc5c1843b 100755
--- a/tools/net/ynl/pyynl/cli.py
+++ b/tools/net/ynl/pyynl/cli.py
@@ -144,16 +144,17 @@ def main():
ops = [ (item[0], json.loads(item[1]), args.flags or []) for item in args.multi ]
reply = ynl.do_multi(ops)
output(reply)
- except NlError as e:
- print(e)
- exit(1)
- if args.ntf:
- try:
+ if args.ntf:
for msg in ynl.poll_ntf(duration=args.duration):
output(msg)
- except KeyboardInterrupt:
- pass
+ except NlError as e:
+ print(e)
+ exit(1)
+ except KeyboardInterrupt:
+ pass
+ except BrokenPipeError:
+ pass
if __name__ == "__main__":
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net-next v1] tools: ynl: handle broken pipe gracefully in CLI
2025-05-08 11:21 [PATCH net-next v1] tools: ynl: handle broken pipe gracefully in CLI Donald Hunter
@ 2025-05-08 13:47 ` Jakub Kicinski
2025-05-09 23:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2025-05-08 13:47 UTC (permalink / raw)
To: Donald Hunter
Cc: netdev, David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Jan Stancek, donald.hunter
On Thu, 8 May 2025 12:21:02 +0100 Donald Hunter wrote:
> When sending YNL CLI output into a pipe, closing the pipe causes a
> BrokenPipeError. E.g. running the following and quitting less:
>
> ./tools/net/ynl/pyynl/cli.py --family rt-link --dump getlink | less
> Traceback (most recent call last):
> File "/home/donaldh/net-next/./tools/net/ynl/pyynl/cli.py", line 160, in <module>
> main()
> ~~~~^^
> File "/home/donaldh/net-next/./tools/net/ynl/pyynl/cli.py", line 142, in main
> output(reply)
> ~~~~~~^^^^^^^
> File "/home/donaldh/net-next/./tools/net/ynl/pyynl/cli.py", line 97, in output
> pprint.PrettyPrinter().pprint(msg)
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
> [...]
> BrokenPipeError: [Errno 32] Broken pipe
>
> Consolidate the try block for ops and notifications, and gracefully
> handle the BrokenPipeError by adding an exception handler to the
> consolidated try block.
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v1] tools: ynl: handle broken pipe gracefully in CLI
2025-05-08 11:21 [PATCH net-next v1] tools: ynl: handle broken pipe gracefully in CLI Donald Hunter
2025-05-08 13:47 ` Jakub Kicinski
@ 2025-05-09 23:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-05-09 23:50 UTC (permalink / raw)
To: Donald Hunter
Cc: netdev, kuba, davem, edumazet, pabeni, horms, jstancek,
donald.hunter
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 8 May 2025 12:21:02 +0100 you wrote:
> When sending YNL CLI output into a pipe, closing the pipe causes a
> BrokenPipeError. E.g. running the following and quitting less:
>
> ./tools/net/ynl/pyynl/cli.py --family rt-link --dump getlink | less
> Traceback (most recent call last):
> File "/home/donaldh/net-next/./tools/net/ynl/pyynl/cli.py", line 160, in <module>
> main()
> ~~~~^^
> File "/home/donaldh/net-next/./tools/net/ynl/pyynl/cli.py", line 142, in main
> output(reply)
> ~~~~~~^^^^^^^
> File "/home/donaldh/net-next/./tools/net/ynl/pyynl/cli.py", line 97, in output
> pprint.PrettyPrinter().pprint(msg)
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
> [...]
> BrokenPipeError: [Errno 32] Broken pipe
>
> [...]
Here is the summary with links:
- [net-next,v1] tools: ynl: handle broken pipe gracefully in CLI
https://git.kernel.org/netdev/net-next/c/0df6932485a0
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-05-09 23:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-08 11:21 [PATCH net-next v1] tools: ynl: handle broken pipe gracefully in CLI Donald Hunter
2025-05-08 13:47 ` Jakub Kicinski
2025-05-09 23:50 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).