Remove extra newline in lang.sh. Change parsing queue to writing queue

This commit is contained in:
kuben
2019-09-19 09:55:42 +02:00
parent 9f5078611c
commit 9097a98884
4 changed files with 15 additions and 20 deletions

View File

@@ -89,14 +89,12 @@ def clean_up():
modules.stop_all()
sys.exit(0)
def queue_parse_job(job):
common.parsing_queue.put(job)
def keep_fifo_open():
with open(config.fifo_file_status, 'w', buffering=1) as fifo_write:
while True:
fifo_write.write('HEARTBEAT\n')
time.sleep(30)
def put_fifo_in_queue():
with open(config.fifo_file_status, 'r', buffering=1) as fifo_read:
# Let parser read from fifo
@@ -108,7 +106,8 @@ def put_fifo_in_queue():
if len(data) == 0:
common.logger.debug("Writer closed")
break
queue_parse_job(data)
data = data.rstrip() # Remove trailing newlines
common.write_queue.put(lemonparser.parse_line(data))
except BrokenPipeError:
common.logger.debug('Broken pipe in parse status thread, exiting')
common.health_logger.info('Broken pipe in parse status thread, exiting')
@@ -118,24 +117,20 @@ def put_fifo_in_queue():
common.health_logger.info('Unknown exception in parse status thread, exiting')
clean_up()
def parse_status():
def write_parsed():
# Write parse entries in queue to lemonbar
global p_lemonbar
p_lemonbar = subprocess.Popen(config.lemonbar_args, stdin=subprocess.PIPE
, stdout=subprocess.PIPE, text=True)
while True:
data = common.parsing_queue.get() # Blocking read
data = common.write_queue.get() # Blocking read
if data is None:
common.logger.debug('Queue closed')
common.health_logger.info('Queue closed')
break
# Ugly temporary solution
if (isinstance(data, list)):
psd = data[0]
else:
psd = lemonparser.parse_line(data)
p_lemonbar.stdin.write(psd + '\n')
p_lemonbar.stdin.write(data + '\n')
p_lemonbar.stdin.flush()
#common.logger.debug('Read: "{0}"'.format(data))
#common.logger.debug('Parsed "{0}"'.format(psd))
@@ -224,12 +219,12 @@ if __name__ == "__main__":
signal.signal(signal.SIGTERM, handle_exit)
signal.signal(signal.SIGINT, handle_exit)
common.parsing_queue = queue.Queue()
common.write_queue = queue.Queue()
# Start writing and reading threads
# Create readers before writers
i3_thread(target = exec_commands, desc='Exec commands thread')
i3_thread(target = parse_status, desc='Parse status thread')
i3_thread(target = write_parsed, desc='Write parsed status thread')
i3_thread(target = keep_fifo_open, desc='')
i3_thread(target = put_fifo_in_queue, desc='')
modules.start_all()