Define KeyboardInterrupt Exception Handler in wmlxgettext
Note: The signal class object was used to avoid wrapping the entire main routine in a try...except clause.
This commit is contained in:
parent
e35690c8f9
commit
78f37713f5
1 changed files with 12 additions and 0 deletions
|
@ -34,6 +34,7 @@
|
|||
import os
|
||||
import re
|
||||
import sys
|
||||
import signal
|
||||
import warnings
|
||||
import argparse
|
||||
from datetime import datetime
|
||||
|
@ -162,6 +163,7 @@ def commandline(args):
|
|||
|
||||
|
||||
def main():
|
||||
signal.signal(signal.SIGINT, sigint_handler)
|
||||
args = commandline(sys.argv[1:])
|
||||
pywmlx.ansi_setEnabled(args.text_col)
|
||||
pywmlx.wincol_setEnabled(args.text_col)
|
||||
|
@ -264,5 +266,15 @@ def main():
|
|||
|
||||
|
||||
|
||||
def sigint_handler(signal, frame):
|
||||
"""This function defines what happens when the SIGINT signal is encountered by pressing ctrl-c during runtime.
|
||||
When ctrl-c is pressed, a one-line message is displayed and Python exits with Status 0, which refers to successful termination.
|
||||
This overrides Python's default behavior of displaying a traceback when ctrl-c is pressed.
|
||||
"""
|
||||
print ('Aborted by pressing ctrl-c')
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Add table
Reference in a new issue