Sửa lỗi trực tiếp trên window

This commit is contained in:
2026-08-11 09:51:13 +07:00
parent aae0b05473
commit f8cb2c6a5e
16 changed files with 10409 additions and 1820 deletions
+20 -3
View File
@@ -573,7 +573,7 @@ def _carla_osc_ready() -> bool:
import socket
port = _carla_osc_port()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("127.0.0.1", port))
s.bind(("0.0.0.0", port))
s.close()
return False
except OSError:
@@ -749,12 +749,20 @@ async def carla_stop(authorization: Optional[str] = Header(None)):
_send_carla_all_notes_off()
except Exception:
pass
# 2. Terminate tiến trình Carla đã spawn
# 2. Terminate tiến trình Carla đã spawn — Windows PHẢI giết cả process
# tree (Carla.exe spawn carla-backend child giữ cổng OSC 22752; terminate
# đơn lẻ chỉ giết cha → child sống → cổng chưa giải phóng → lần mở sau
# open_in_carla thấy already_running dù Carla đã chết → GUI không xuất
# hiện lại (Bug 3 standalone)).
killed = 0
_prune_carla_processes()
for proc in list(_CARLA_PROCESSES):
try:
proc.terminate()
if os.name == "nt" and proc.pid:
subprocess.run(["taskkill", "/PID", str(proc.pid), "/T", "/F"],
capture_output=True, timeout=15)
else:
proc.terminate()
except Exception:
pass
# Chờ tiến trình thoát (tối đa ~2s) rồi kill mạnh nếu còn sống
@@ -774,6 +782,15 @@ async def carla_stop(authorization: Optional[str] = Header(None)):
except Exception:
pass
_CARLA_PROCESSES.clear()
# 3. Chờ cổng OSC UDP thực sự được giải phóng (child có thể thoát chậm
# hơn cha) — nếu không, mở lại Carla ngay sẽ bị gate already_running.
try:
import time as _t
deadline = _t.time() + 5.0
while _t.time() < deadline and _carla_osc_ready():
_t.sleep(0.1)
except Exception:
pass
return {
"success": True,
"stopped": True,