[core] Non-blocking input thread for i3bar events

Make input thread non-blocking by using select(). This increases the CPU
utilization a bit (depending on the timeout), but makes the thread exit
cleanly, even if an exception is thrown in the main thread.

see #23
This commit is contained in:
Tobi-wan Kenobi 2016-12-10 13:45:54 +01:00
parent 0489ce1b51
commit 029492e16d
4 changed files with 45 additions and 12 deletions

View file

@ -29,9 +29,10 @@ class TestCmusModule(unittest.TestCase):
def test_widgets(self):
self.assertTrue(len(self.module.widgets()), 5)
@mock.patch("select.select")
@mock.patch("subprocess.Popen")
@mock.patch("sys.stdin")
def test_interaction(self, mock_input, mock_output):
def test_interaction(self, mock_input, mock_output, mock_select):
events = [
{"widget": "cmus.shuffle", "action": "cmus-remote -S"},
{"widget": "cmus.repeat", "action": "cmus-remote -R"},
@ -40,6 +41,8 @@ class TestCmusModule(unittest.TestCase):
{"widget": "cmus.main", "action": "cmus-remote -u"},
]
mock_select.return_value = (1,2,3)
for event in events:
mock_input.readline.return_value = json.dumps({
"name": self.module.id,