mirror of https://git.48k.eu/ogcli/
ogcli: add SIGINT handler
if user presses ctrl-c, interrupt ongoing operation to avoid python backtrace.master
parent
da8f8e8009
commit
b91ab6ef78
4
ogcli
4
ogcli
|
@ -17,10 +17,14 @@ import sys
|
||||||
|
|
||||||
OG_CLI_CFG_PATH = "/opt/opengnsys/etc/ogcli.json"
|
OG_CLI_CFG_PATH = "/opt/opengnsys/etc/ogcli.json"
|
||||||
|
|
||||||
|
def sigint_handler(signum, frame):
|
||||||
|
print("User has pressed ctrl-C, interrupting...")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
class CLI():
|
class CLI():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
signal.signal(signal.SIGPIPE, signal.SIG_IGN)
|
signal.signal(signal.SIGPIPE, signal.SIG_IGN)
|
||||||
|
signal.signal(signal.SIGINT, sigint_handler)
|
||||||
try:
|
try:
|
||||||
with open(OG_CLI_CFG_PATH, 'r') as json_file:
|
with open(OG_CLI_CFG_PATH, 'r') as json_file:
|
||||||
self.cfg = json.load(json_file)
|
self.cfg = json.load(json_file)
|
||||||
|
|
Loading…
Reference in New Issue