Skip to content

Commit d6d024d

Browse files
author
tomaszs
committed
code formatting
1 parent 20aada8 commit d6d024d

2 files changed

Lines changed: 14 additions & 25 deletions

File tree

examples/application_inputs_file.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,12 @@ async def main():
153153
except KeyboardInterrupt:
154154
print("Shutting down...")
155155
finally:
156-
# Signal the watcher thread to stop
157156
stop_watching.set()
158157
input_thread.join()
159-
160-
# Cancel all tasks
161158
for task in tasks:
162159
if not task.done():
163160
task.cancel()
164161

165-
# Wait for tasks to be cancelled
166162
await asyncio.gather(*tasks, return_exceptions=True)
167163

168164

examples/application_inputs_simple.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,24 @@ def input_reader():
6868

6969

7070
# Function to process the input queue and send messages via WebSocket
71-
async def handle_keyboard_input():
71+
async def handle_input_queue():
7272
while True:
7373
# Check the regular queue in a non-blocking way
7474
try:
7575
# Use asyncio.sleep(0) to yield control back to the event loop regularly
7676
await asyncio.sleep(0.1)
77-
78-
# Check if there's input to process (non-blocking)
79-
if not input_queue.empty():
80-
user_input = input_queue.get_nowait()
81-
if user_input:
82-
# Create the message in the required format
83-
message = AddInput(input=user_input, immediate=True, interrupt_response=True).asdict()
84-
# Send the message through the WebSocket
85-
await client.websocket.send(json.dumps(message))
86-
print(f"Message sent: {json.dumps(message)}")
87-
# Mark the task as done
88-
input_queue.task_done()
77+
if input_queue.empty():
78+
continue
79+
80+
user_input = input_queue.get_nowait()
81+
if user_input:
82+
# Create the message in the required format
83+
message = AddInput(input=user_input, immediate=True, interrupt_response=True).asdict()
84+
# Send the message through the WebSocket
85+
await client.websocket.send(json.dumps(message))
86+
print(f"Message sent: {json.dumps(message)}")
87+
# Mark the task as done
88+
input_queue.task_done()
8989
except queue.Empty:
9090
# Queue is empty, just continue
9191
pass
@@ -117,10 +117,8 @@ async def main():
117117
),
118118
)
119119
),
120-
# Start the audio playback handler
121120
asyncio.create_task(audio_playback(audio_queue)),
122-
# Start the keyboard input handler (polls the queue)
123-
asyncio.create_task(handle_keyboard_input()),
121+
asyncio.create_task(handle_input_queue()),
124122
]
125123

126124
try:
@@ -132,15 +130,10 @@ async def main():
132130
except KeyboardInterrupt:
133131
print("Shutting down...")
134132
finally:
135-
# Signal the input thread to stop
136133
stop_input_thread.set()
137-
138-
# Cancel all tasks
139134
for task in tasks:
140135
if not task.done():
141136
task.cancel()
142-
143-
# Wait for tasks to be cancelled
144137
await asyncio.gather(*tasks, return_exceptions=True)
145138

146139

0 commit comments

Comments
 (0)