Spaces:
Runtime error
Runtime error
da03
commited on
Commit
·
a2d7c6c
1
Parent(s):
2da2765
main.py
CHANGED
@@ -249,45 +249,44 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
249 |
print(f"[{current_time:.3f}] Already processing an input. Will check again later.")
|
250 |
return
|
251 |
|
252 |
-
# Set is_processing to True
|
253 |
is_processing = True
|
254 |
|
255 |
queue_size = input_queue.qsize()
|
256 |
print(f"[{current_time:.3f}] Processing next input. Queue size: {queue_size}")
|
257 |
|
258 |
-
#
|
259 |
-
|
|
|
|
|
|
|
260 |
while not input_queue.empty():
|
261 |
-
|
262 |
input_queue.task_done()
|
263 |
-
|
264 |
-
# Find all interesting inputs
|
265 |
-
interesting_indices = [i for i, data in enumerate(all_inputs)
|
266 |
-
if data.get("is_left_click") or
|
267 |
-
data.get("is_right_click") or
|
268 |
-
(data.get("keys_down") and len(data.get("keys_down")) > 0) or
|
269 |
-
(data.get("keys_up") and len(data.get("keys_up")) > 0)]
|
270 |
-
|
271 |
-
if interesting_indices:
|
272 |
-
# There are interesting events - take the most recent one
|
273 |
-
idx = interesting_indices[-1]
|
274 |
-
next_input = all_inputs[idx]
|
275 |
-
skipped = len(all_inputs) - 1 # We're processing one, so skipped = total - 1
|
276 |
|
277 |
-
#
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
|
292 |
while True:
|
293 |
try:
|
|
|
249 |
print(f"[{current_time:.3f}] Already processing an input. Will check again later.")
|
250 |
return
|
251 |
|
252 |
+
# Set is_processing to True before proceeding
|
253 |
is_processing = True
|
254 |
|
255 |
queue_size = input_queue.qsize()
|
256 |
print(f"[{current_time:.3f}] Processing next input. Queue size: {queue_size}")
|
257 |
|
258 |
+
# Initialize variables to track progress
|
259 |
+
skipped = 0
|
260 |
+
latest_input = None
|
261 |
+
|
262 |
+
# Process the queue one item at a time
|
263 |
while not input_queue.empty():
|
264 |
+
current_input = await input_queue.get()
|
265 |
input_queue.task_done()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
|
267 |
+
# Always update the latest input
|
268 |
+
latest_input = current_input
|
269 |
+
|
270 |
+
# Check if this is an interesting event
|
271 |
+
is_interesting = (current_input.get("is_left_click") or
|
272 |
+
current_input.get("is_right_click") or
|
273 |
+
(current_input.get("keys_down") and len(current_input.get("keys_down")) > 0) or
|
274 |
+
(current_input.get("keys_up") and len(current_input.get("keys_up")) > 0))
|
275 |
+
|
276 |
+
# Process immediately if interesting
|
277 |
+
if is_interesting:
|
278 |
+
print(f"[{current_time:.3f}] Found interesting input (skipped {skipped} events)")
|
279 |
+
asyncio.create_task(process_input(current_input))
|
280 |
+
return
|
281 |
+
|
282 |
+
# Otherwise, continue to the next item
|
283 |
+
skipped += 1
|
284 |
+
|
285 |
+
# If this is the last item and no interesting inputs were found
|
286 |
+
if input_queue.empty():
|
287 |
+
print(f"[{current_time:.3f}] No interesting inputs, processing latest movement (skipped {skipped-1} events)")
|
288 |
+
asyncio.create_task(process_input(latest_input))
|
289 |
+
return
|
290 |
|
291 |
while True:
|
292 |
try:
|