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