import queue import time import threading def main(): print("Hello There") que = queue.Queue() event = threading.Event() config = {'output': '/tmp/test_out', 'input': '/tmp/test_in'} #input(que) input_thread = threading.Thread(target=handle_input, args=(que,event,config)) input_thread.daemon = True input_thread.start() #output(que) output_thread = threading.Thread(target=handle_output, args=(que,event,config)) output_thread.daemon = True output_thread.start() for num in range(21): print(f"wait till full: {num}/20", end='\r') time.sleep(0.5) print("\nDone!") event.set() def handle_input(que, event, config): loop = 0 file = config['input'] while not event.is_set(): message = f"{time.time()} | Hi! | {file} | {loop}" que.put(message) loop = loop + 1 time.sleep(1) def handle_output(que, event, config): file = '/tmp/test_out' future_file = config['output'] with open(file, 'a') as out_file: while not event.is_set(): message = que.get() out_file.write(f"{future_file} | {message}\r\n") out_file.flush() time.sleep(1) if __name__ == "__main__": main() print("Bye now!") exit(0)