[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

@ -24,14 +24,16 @@ class TestCPUModule(unittest.TestCase):
for widget in self.module.widgets():
self.assertEquals(len(widget.full_text()), len("100.00%"))
@mock.patch("select.select")
@mock.patch("subprocess.Popen")
@mock.patch("sys.stdin")
def test_leftclick(self, mock_input, mock_output):
def test_leftclick(self, mock_input, mock_output, mock_select):
mock_input.readline.return_value = json.dumps({
"name": self.module.id,
"button": bumblebee.input.LEFT_MOUSE,
"instance": None
})
mock_select.return_value = (1,2,3)
self.engine.input.start()
self.engine.input.stop()
mock_input.readline.assert_any_call()