import queue import time import threading def main(): print("Hello There") que = queue.Queue() event = threading.Event() #input(que) input_thread = threading.Thread(target=input, args=(que,event)) input_thread.daemon = True input_thread.start() #output(que) output_thread = threading.Thread(target=output, args=(que,event)) 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 input(que, event): loop = 0 while not event: message = f"{time.time()} | Hi! {loop}" que.put(message) loop = loop + 1 time.sleep(1) def output(que, event): file = '/tmp/test_out' with open(file, 'a') as out_file: while not event: message = que.get() out_file.write(f"{message}\r\n") out_file.flush() time.sleep(1) out_file.close() if __name__ == "__main__": main() print("Bye now!") exit(0)