[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

@ -4,6 +4,7 @@ import sys
import json
import uuid
import time
import select
import threading
import bumblebee.util
@ -15,6 +16,13 @@ WHEEL_DOWN = 5
def read_input(inp):
"""Read i3bar input and execute callbacks"""
while inp.running:
for thread in threading.enumerate():
if thread.name == "MainThread" and not thread.is_alive():
return
rlist, _, _ = select.select([sys.stdin], [], [], 1)
if not rlist:
continue
line = sys.stdin.readline().strip(",").strip()
inp.has_event = True
try: