Spaces:
Runtime error
Runtime error
da03
commited on
Commit
·
d20b0fd
1
Parent(s):
a5eff0d
main.py
CHANGED
|
@@ -234,8 +234,8 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
| 234 |
finally:
|
| 235 |
is_processing = False
|
| 236 |
print(f"[{time.perf_counter():.3f}] Processing complete. Queue size before checking next input: {input_queue.qsize()}")
|
| 237 |
-
# Check if we have more inputs to process after this one
|
| 238 |
-
asyncio.create_task(process_next_input())
|
| 239 |
|
| 240 |
async def process_next_input():
|
| 241 |
nonlocal is_processing
|
|
@@ -243,6 +243,7 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
| 243 |
current_time = time.perf_counter()
|
| 244 |
if input_queue.empty():
|
| 245 |
print(f"[{current_time:.3f}] No inputs to process. Queue is empty.")
|
|
|
|
| 246 |
return
|
| 247 |
|
| 248 |
if is_processing:
|
|
@@ -255,37 +256,46 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
| 255 |
queue_size = input_queue.qsize()
|
| 256 |
print(f"[{current_time:.3f}] Processing next input. Queue size: {queue_size}")
|
| 257 |
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 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 |
-
process_input(current_input)
|
| 280 |
-
|
| 281 |
-
# Otherwise, continue to the next item
|
| 282 |
-
skipped += 1
|
| 283 |
|
| 284 |
-
#
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
|
| 290 |
while True:
|
| 291 |
try:
|
|
@@ -306,7 +316,7 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
| 306 |
if not is_processing:
|
| 307 |
print(f"[{receive_time:.3f}] Not currently processing, will call process_next_input()")
|
| 308 |
is_processing = True
|
| 309 |
-
asyncio.create_task(process_next_input())
|
| 310 |
else:
|
| 311 |
print(f"[{receive_time:.3f}] Currently processing, new input queued for later")
|
| 312 |
|
|
|
|
| 234 |
finally:
|
| 235 |
is_processing = False
|
| 236 |
print(f"[{time.perf_counter():.3f}] Processing complete. Queue size before checking next input: {input_queue.qsize()}")
|
| 237 |
+
# Check if we have more inputs to process after this one TODO
|
| 238 |
+
#asyncio.create_task(process_next_input())
|
| 239 |
|
| 240 |
async def process_next_input():
|
| 241 |
nonlocal is_processing
|
|
|
|
| 243 |
current_time = time.perf_counter()
|
| 244 |
if input_queue.empty():
|
| 245 |
print(f"[{current_time:.3f}] No inputs to process. Queue is empty.")
|
| 246 |
+
is_processing = False
|
| 247 |
return
|
| 248 |
|
| 249 |
if is_processing:
|
|
|
|
| 256 |
queue_size = input_queue.qsize()
|
| 257 |
print(f"[{current_time:.3f}] Processing next input. Queue size: {queue_size}")
|
| 258 |
|
| 259 |
+
try:
|
| 260 |
+
# Initialize variables to track progress
|
| 261 |
+
skipped = 0
|
| 262 |
+
latest_input = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
+
# Process the queue one item at a time
|
| 265 |
+
while not input_queue.empty():
|
| 266 |
+
current_input = await input_queue.get()
|
| 267 |
+
input_queue.task_done()
|
| 268 |
+
|
| 269 |
+
# Always update the latest input
|
| 270 |
+
latest_input = current_input
|
| 271 |
+
|
| 272 |
+
# Check if this is an interesting event
|
| 273 |
+
is_interesting = (current_input.get("is_left_click") or
|
| 274 |
+
current_input.get("is_right_click") or
|
| 275 |
+
(current_input.get("keys_down") and len(current_input.get("keys_down")) > 0) or
|
| 276 |
+
(current_input.get("keys_up") and len(current_input.get("keys_up")) > 0))
|
| 277 |
+
|
| 278 |
+
# Process immediately if interesting
|
| 279 |
+
if is_interesting:
|
| 280 |
+
print(f"[{current_time:.3f}] Found interesting input (skipped {skipped} events)")
|
| 281 |
+
await process_input(current_input) # AWAIT here instead of creating a task
|
| 282 |
+
is_processing = False
|
| 283 |
+
return
|
| 284 |
+
|
| 285 |
+
# Otherwise, continue to the next item
|
| 286 |
+
skipped += 1
|
| 287 |
+
|
| 288 |
+
# If this is the last item and no interesting inputs were found
|
| 289 |
+
if input_queue.empty():
|
| 290 |
+
print(f"[{current_time:.3f}] No interesting inputs, processing latest movement (skipped {skipped-1} events)")
|
| 291 |
+
await process_input(latest_input) # AWAIT here instead of creating a task
|
| 292 |
+
is_processing = False
|
| 293 |
+
return
|
| 294 |
+
except Exception as e:
|
| 295 |
+
print(f"[{current_time:.3f}] Error in process_next_input: {e}")
|
| 296 |
+
import traceback
|
| 297 |
+
traceback.print_exc()
|
| 298 |
+
is_processing = False # Make sure to reset on error
|
| 299 |
|
| 300 |
while True:
|
| 301 |
try:
|
|
|
|
| 316 |
if not is_processing:
|
| 317 |
print(f"[{receive_time:.3f}] Not currently processing, will call process_next_input()")
|
| 318 |
is_processing = True
|
| 319 |
+
asyncio.create_task(process_next_input()) # Create task but don't await it
|
| 320 |
else:
|
| 321 |
print(f"[{receive_time:.3f}] Currently processing, new input queued for later")
|
| 322 |
|