Working fifo input now.
This commit is contained in:
parent
8f80c98c77
commit
b4068ff0de
@ -1,6 +1,8 @@
|
|||||||
import queue
|
import queue
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
import re
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("Hello There")
|
print("Hello There")
|
||||||
@ -10,37 +12,58 @@ def main():
|
|||||||
config = {'output': '/tmp/test_out', 'input': '/tmp/test_in'}
|
config = {'output': '/tmp/test_out', 'input': '/tmp/test_in'}
|
||||||
|
|
||||||
#input(que)
|
#input(que)
|
||||||
input_thread = threading.Thread(target=handle_input, args=(que,event,config))
|
input_thread = threading.Thread(target=handle_input, args=(que, event, config))
|
||||||
input_thread.daemon = True
|
input_thread.daemon = True
|
||||||
input_thread.start()
|
input_thread.start()
|
||||||
|
|
||||||
#output(que)
|
#output(que)
|
||||||
output_thread = threading.Thread(target=handle_output, args=(que,event,config))
|
output_thread = threading.Thread(target=handle_output, args=(que, event, config))
|
||||||
output_thread.daemon = True
|
output_thread.daemon = True
|
||||||
output_thread.start()
|
output_thread.start()
|
||||||
|
|
||||||
for num in range(21):
|
countdown(config, event)
|
||||||
print(f"wait till full: {num}/20", end='\r')
|
|
||||||
|
def countdown(config, event):
|
||||||
|
print(f"Speak to: {config['input']}")
|
||||||
|
print(f"Output is going to be: {config['output']}")
|
||||||
|
num = 0
|
||||||
|
while not event.is_set():
|
||||||
|
print(f"wait till full: {num}/~", end='\r')
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
num = num + 1
|
||||||
print("\nDone!")
|
print("\nDone!")
|
||||||
event.set()
|
|
||||||
|
|
||||||
def handle_input(que, event, config):
|
def handle_input(que, event, config):
|
||||||
loop = 0
|
|
||||||
file = config['input']
|
file = config['input']
|
||||||
|
try:
|
||||||
|
os.mkfifo(file)
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
with open(file, 'r') as in_fifo:
|
||||||
while not event.is_set():
|
while not event.is_set():
|
||||||
message = f"{time.time()} | Hi! | {file} | {loop}"
|
fifo_read = in_fifo.readline().rsplit('\n')
|
||||||
|
if not fifo_read:
|
||||||
|
continue
|
||||||
|
message = fifo_read
|
||||||
que.put(message)
|
que.put(message)
|
||||||
loop = loop + 1
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
def handle_output(que, event, config):
|
def handle_output(que, event, config):
|
||||||
file = '/tmp/test_out'
|
file = config['output']
|
||||||
future_file = config['output']
|
|
||||||
with open(file, 'a') as out_file:
|
with open(file, 'a') as out_file:
|
||||||
while not event.is_set():
|
while not event.is_set():
|
||||||
|
try:
|
||||||
message = que.get()
|
message = que.get()
|
||||||
out_file.write(f"{future_file} | {message}\r\n")
|
except queue.Empty:
|
||||||
|
continue
|
||||||
|
if message == "":
|
||||||
|
continue
|
||||||
|
elif 'EXIT' in message:
|
||||||
|
event.set()
|
||||||
|
out_file.write(f"{time.time()} | Bye!\r\n")
|
||||||
|
out_file.flush()
|
||||||
|
else:
|
||||||
|
out_file.write(f"{time.time()} | {message[0]}\r\n")
|
||||||
out_file.flush()
|
out_file.flush()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user