diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-01-22 17:19:50 +0100 |
|---|---|---|
| committer | Christian Breunig <christian@breunig.cc> | 2026-01-22 17:30:18 +0100 |
| commit | 09855a7790d0a5a2eef4cbf6f60f84f2f9f8981e (patch) | |
| tree | 46d4ca030a9961967cb5cd910373071fa8b8cf71 /python | |
| parent | 41aa42fec49399a3cee7c772d2799b1c17490401 (diff) | |
| download | vyos-1x-09855a7790d0a5a2eef4cbf6f60f84f2f9f8981e.tar.gz vyos-1x-09855a7790d0a5a2eef4cbf6f60f84f2f9f8981e.zip | |
T8154: make catch_broken_pipe decorator to common vyos.utils.io function
This adds the capability to make it re-usable in other code paths.
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/utils/io.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/python/vyos/utils/io.py b/python/vyos/utils/io.py index 0883376d1..3efb55ddc 100644 --- a/python/vyos/utils/io.py +++ b/python/vyos/utils/io.py @@ -111,3 +111,14 @@ def select_entry(l: list, list_msg: str = '', prompt_msg: str = '', select = ask_input(prompt_msg, default=default_entry, numeric_only=True, valid_responses=valid_entry) return next(filter(lambda x: x[0] == select, en))[1] + +def catch_broken_pipe(func): + import os + import sys + def wrapped(*args, **kwargs): + try: + func(*args, **kwargs) + except (BrokenPipeError, KeyboardInterrupt): + # Flush output to /dev/null and bail out. + os.dup2(os.open(os.devnull, os.O_WRONLY), sys.stdout.fileno()) # pylint: disable = no-member + return wrapped |
