Skip to content

Commit

Permalink
Add SIGINT handle to main loop
Browse files Browse the repository at this point in the history
  • Loading branch information
amanusk committed Jul 16, 2017
1 parent d4f8155 commit b56ed9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion s_tui/HelperFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import subprocess
import re

__version__ = "0.3.7"
__version__ = "0.3.8"
TURBO_MSR = 429

def get_processor_name():
Expand Down
12 changes: 11 additions & 1 deletion s_tui/s_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import time
import psutil
import urwid
import signal

from AboutMenu import AboutMenu
from ComplexBarGraphs import LabeledBarGraph
Expand Down Expand Up @@ -76,6 +77,8 @@
"




class ViListBox(urwid.ListBox):
# Catch key presses in box and pass them as arrow keys
def keypress(self, size, key):
Expand Down Expand Up @@ -139,8 +142,13 @@ def set_stress_process(self, proc):
return True



class MainLoop(urwid.MainLoop):
def signal_handler(signal, frame):
"""singnal handler for properly exiting Ctrl+C"""
logging.debug(graph_controller.mode.get_stress_process())
kill_child_processes(graph_controller.mode.get_stress_process())
raise urwid.ExitMainLoop()

""" Inherit urwid Mainloop to catch special charachter inputs"""
def unhandled_input(self, input):
logging.debug('Caught ' + str(input))
Expand All @@ -152,6 +160,8 @@ def unhandled_input(self, input):
if input == 'esc':
graph_controller.view.on_stress_menu_close()

signal.signal(signal.SIGINT, signal_handler)


class GraphView(urwid.WidgetPlaceholder):
"""
Expand Down

0 comments on commit b56ed9d

Please sign in to comment.