Fix stop_stream: add lock and emit response
Browse files
app.py
CHANGED
|
@@ -385,11 +385,12 @@ def start_stream(n_steps=8, cfg=0.0, fps=30, clamp=True):
|
|
| 385 |
|
| 386 |
def stop_stream():
|
| 387 |
global stream_thread, stream_running
|
| 388 |
-
|
| 389 |
-
stream_thread
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
|
|
|
| 393 |
|
| 394 |
@socketio.on_error_default
|
| 395 |
def default_error_handler(e):
|
|
@@ -462,7 +463,14 @@ def handle_action(data):
|
|
| 462 |
@socketio.on('stop_stream')
|
| 463 |
def handle_stop_stream():
|
| 464 |
print('Stopping stream')
|
| 465 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
|
| 467 |
# --------------------------
|
| 468 |
# Entrypoint
|
|
|
|
| 385 |
|
| 386 |
def stop_stream():
|
| 387 |
global stream_thread, stream_running
|
| 388 |
+
with stream_lock:
|
| 389 |
+
if stream_thread is not None:
|
| 390 |
+
stream_thread.stop()
|
| 391 |
+
stream_thread.join(timeout=1.0)
|
| 392 |
+
stream_thread = None
|
| 393 |
+
stream_running = False
|
| 394 |
|
| 395 |
@socketio.on_error_default
|
| 396 |
def default_error_handler(e):
|
|
|
|
| 463 |
@socketio.on('stop_stream')
|
| 464 |
def handle_stop_stream():
|
| 465 |
print('Stopping stream')
|
| 466 |
+
try:
|
| 467 |
+
stop_stream()
|
| 468 |
+
emit('stream_stopped', {'status': 'ok'})
|
| 469 |
+
except Exception as e:
|
| 470 |
+
print(f"Error stopping stream: {e}")
|
| 471 |
+
import traceback
|
| 472 |
+
traceback.print_exc()
|
| 473 |
+
emit('error', {'message': f'Failed to stop stream: {str(e)}'})
|
| 474 |
|
| 475 |
# --------------------------
|
| 476 |
# Entrypoint
|