Restart Docker Desktop on Windows to fix WSL2 backend issues. Returns: Tuple of (success, message)
()
| 193 | |
| 194 | |
| 195 | def _restart_docker_desktop_windows() -> tuple[bool, str]: |
| 196 | """Restart Docker Desktop on Windows to fix WSL2 backend issues. |
| 197 | |
| 198 | Returns: |
| 199 | Tuple of (success, message) |
| 200 | """ |
| 201 | print(" Attempting to restart Docker Desktop to fix WSL2 backend...", flush=True) |
| 202 | |
| 203 | # Find Docker Desktop executable |
| 204 | docker_path = _find_docker_desktop_executable() |
| 205 | if not docker_path: |
| 206 | return False, "Docker Desktop executable not found" |
| 207 | |
| 208 | # Kill existing Docker Desktop processes |
| 209 | print(" Stopping Docker Desktop...", flush=True) |
| 210 | _kill_docker_desktop_windows() |
| 211 | |
| 212 | # Wait a bit for cleanup |
| 213 | time.sleep(5) |
| 214 | |
| 215 | # Start Docker Desktop |
| 216 | print(" Starting Docker Desktop...", flush=True) |
| 217 | try: |
| 218 | subprocess.Popen( |
| 219 | [docker_path], |
| 220 | stdout=subprocess.DEVNULL, |
| 221 | stderr=subprocess.DEVNULL, |
| 222 | ) |
| 223 | |
| 224 | # Wait for Docker Desktop and WSL2 backend to start |
| 225 | print( |
| 226 | " Waiting for Docker Desktop and WSL2 backend to initialize...", flush=True |
| 227 | ) |
| 228 | |
| 229 | for attempt in range(120): # Try for up to 2 minutes |
| 230 | time.sleep(1) |
| 231 | |
| 232 | # Check if Docker engine is responding |
| 233 | if is_docker_available(): |
| 234 | # Also verify WSL2 backend is running |
| 235 | wsl_running, _ = _check_wsl2_docker_backend() |
| 236 | if wsl_running: |
| 237 | return ( |
| 238 | True, |
| 239 | "Docker Desktop restarted successfully - WSL2 backend is running", |
| 240 | ) |
| 241 | |
| 242 | # Print progress every 15 seconds |
| 243 | if (attempt + 1) % 15 == 0: |
| 244 | print(f" Still waiting ({attempt + 1}s)...", flush=True) |
| 245 | |
| 246 | return ( |
| 247 | False, |
| 248 | "Docker Desktop started but WSL2 backend failed to initialize within 2 minutes", |
| 249 | ) |
| 250 | |
| 251 | except KeyboardInterrupt as ki: |
| 252 | handle_keyboard_interrupt(ki) |
no test coverage detected