ogcli: ignore SIGPIPE

# ogcli list scope | less
 ... leave it open for one minute, then press 'q' to exit less

 it shows:

Traceback (most recent call last):
  File "/usr/bin/ogcli", line 60, in <module>
    CLI()
  File "/usr/bin/ogcli", line 56, in __init__
    getattr(self.ogcli, args.command)(sys.argv[2:])
  File "/opt/opengnsys/bin/cli/cli.py", line 93, in list
    OgScope.list_scopes(self.rest)
  File "/opt/opengnsys/bin/cli/objects/scopes.py", line 18, in list_scopes
    print_json(r.text)
  File "/opt/opengnsys/bin/cli/utils.py", line 34, in print_json
    print(json.dumps(payload, sort_keys=True, indent=2))
BrokenPipeError: [Errno 32] Broken pipe

It seems that the request library in python leaves the socket open
while it still displays the listing.

Ignore SIGPIPE which reports that socket is not there anymore, it is
a common practise to ignore this signal in socket.
master v0.3.3-2
OpenGnSys Support Team 2023-11-03 10:36:34 +01:00
parent 4bf4f91f54
commit 09cb99b057
1 changed files with 2 additions and 0 deletions

2
ogcli
View File

@ -10,6 +10,7 @@
from inspect import ismethod, getmembers
from cli.cli import OgCLI
import signal
import argparse
import json
import sys
@ -19,6 +20,7 @@ OG_CLI_CFG_PATH = "/opt/opengnsys/etc/ogcli.json"
class CLI():
def __init__(self):
signal.signal(signal.SIGPIPE, signal.SIG_IGN)
try:
with open(OG_CLI_CFG_PATH, 'r') as json_file:
self.cfg = json.load(json_file)