Spaces:
Runtime error
Runtime error
da03
commited on
Commit
·
a52dde1
1
Parent(s):
f096c36
main.py
CHANGED
@@ -298,6 +298,7 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
298 |
timeout_warning_sent = False
|
299 |
timeout_task = None
|
300 |
connection_active = True # Flag to track if connection is still active
|
|
|
301 |
|
302 |
# Start timing for global FPS calculation
|
303 |
connection_start_time = time.perf_counter()
|
@@ -309,7 +310,7 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
309 |
|
310 |
# Add a function to reset the simulation
|
311 |
async def reset_simulation():
|
312 |
-
nonlocal previous_frame, hidden_states, keys_down, frame_num, is_processing, input_queue
|
313 |
# Keep the client settings during reset
|
314 |
temp_client_settings = client_settings.copy()
|
315 |
|
@@ -335,11 +336,13 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
335 |
keys_down = set()
|
336 |
frame_num = -1
|
337 |
is_processing = False
|
|
|
338 |
|
339 |
# Restore client settings
|
340 |
client_settings.update(temp_client_settings)
|
341 |
|
342 |
print(f"[{time.perf_counter():.3f}] Simulation reset to initial state (preserved settings: USE_RNN={client_settings['use_rnn']}, SAMPLING_STEPS={client_settings['sampling_steps']})")
|
|
|
343 |
|
344 |
# Send confirmation to client
|
345 |
await websocket.send_json({"type": "reset_confirmed"})
|
@@ -385,7 +388,7 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
385 |
|
386 |
# Add timeout checking function
|
387 |
async def check_timeout():
|
388 |
-
nonlocal timeout_warning_sent, timeout_task, connection_active
|
389 |
|
390 |
while True:
|
391 |
try:
|
@@ -394,6 +397,12 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
394 |
print(f"[{time.perf_counter():.3f}] Connection inactive or WebSocket closed, stopping timeout check for client {client_id}")
|
395 |
return
|
396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
397 |
current_time = time.perf_counter()
|
398 |
time_since_activity = current_time - last_user_activity_time
|
399 |
|
@@ -456,7 +465,7 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
456 |
|
457 |
# Start timeout checking
|
458 |
timeout_task = asyncio.create_task(check_timeout())
|
459 |
-
print(f"[{time.perf_counter():.3f}] Timeout task started for client {client_id}")
|
460 |
|
461 |
async def process_input(data):
|
462 |
nonlocal previous_frame, hidden_states, keys_down, frame_num, frame_count, is_processing
|
@@ -489,6 +498,10 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
489 |
else:
|
490 |
# Update user activity for non-auto inputs
|
491 |
update_user_activity()
|
|
|
|
|
|
|
|
|
492 |
print(f'[{time.perf_counter():.3f}] Processing: x: {x}, y: {y}, is_left_click: {is_left_click}, is_right_click: {is_right_click}, keys_down_list: {keys_down_list}, keys_up_list: {keys_up_list}, time_since_activity: {time.perf_counter() - last_user_activity_time:.3f}')
|
493 |
|
494 |
# Update the set based on the received data
|
|
|
298 |
timeout_warning_sent = False
|
299 |
timeout_task = None
|
300 |
connection_active = True # Flag to track if connection is still active
|
301 |
+
user_has_interacted = False # Flag to track if user has started interacting
|
302 |
|
303 |
# Start timing for global FPS calculation
|
304 |
connection_start_time = time.perf_counter()
|
|
|
310 |
|
311 |
# Add a function to reset the simulation
|
312 |
async def reset_simulation():
|
313 |
+
nonlocal previous_frame, hidden_states, keys_down, frame_num, is_processing, input_queue, user_has_interacted
|
314 |
# Keep the client settings during reset
|
315 |
temp_client_settings = client_settings.copy()
|
316 |
|
|
|
336 |
keys_down = set()
|
337 |
frame_num = -1
|
338 |
is_processing = False
|
339 |
+
user_has_interacted = False # Reset user interaction state
|
340 |
|
341 |
# Restore client settings
|
342 |
client_settings.update(temp_client_settings)
|
343 |
|
344 |
print(f"[{time.perf_counter():.3f}] Simulation reset to initial state (preserved settings: USE_RNN={client_settings['use_rnn']}, SAMPLING_STEPS={client_settings['sampling_steps']})")
|
345 |
+
print(f"[{time.perf_counter():.3f}] User interaction state reset - waiting for user to interact again")
|
346 |
|
347 |
# Send confirmation to client
|
348 |
await websocket.send_json({"type": "reset_confirmed"})
|
|
|
388 |
|
389 |
# Add timeout checking function
|
390 |
async def check_timeout():
|
391 |
+
nonlocal timeout_warning_sent, timeout_task, connection_active, user_has_interacted
|
392 |
|
393 |
while True:
|
394 |
try:
|
|
|
397 |
print(f"[{time.perf_counter():.3f}] Connection inactive or WebSocket closed, stopping timeout check for client {client_id}")
|
398 |
return
|
399 |
|
400 |
+
# Don't start timeout tracking until user has actually interacted
|
401 |
+
if not user_has_interacted:
|
402 |
+
print(f"[{time.perf_counter():.3f}] User hasn't interacted yet, skipping timeout check for client {client_id}")
|
403 |
+
await asyncio.sleep(1) # Check every second
|
404 |
+
continue
|
405 |
+
|
406 |
current_time = time.perf_counter()
|
407 |
time_since_activity = current_time - last_user_activity_time
|
408 |
|
|
|
465 |
|
466 |
# Start timeout checking
|
467 |
timeout_task = asyncio.create_task(check_timeout())
|
468 |
+
print(f"[{time.perf_counter():.3f}] Timeout task started for client {client_id} (waiting for user interaction)")
|
469 |
|
470 |
async def process_input(data):
|
471 |
nonlocal previous_frame, hidden_states, keys_down, frame_num, frame_count, is_processing
|
|
|
498 |
else:
|
499 |
# Update user activity for non-auto inputs
|
500 |
update_user_activity()
|
501 |
+
# Mark that user has started interacting
|
502 |
+
if not user_has_interacted:
|
503 |
+
user_has_interacted = True
|
504 |
+
print(f"[{time.perf_counter():.3f}] User has started interacting with canvas for client {client_id}")
|
505 |
print(f'[{time.perf_counter():.3f}] Processing: x: {x}, y: {y}, is_left_click: {is_left_click}, is_right_click: {is_right_click}, keys_down_list: {keys_down_list}, keys_up_list: {keys_up_list}, time_since_activity: {time.perf_counter() - last_user_activity_time:.3f}')
|
506 |
|
507 |
# Update the set based on the received data
|