Skip to content

Commit 5c96b41

Browse files
committed
feat(compilation): bouton annuler robuste et réactif
- Propagation du signal d'arrêt dans toutes les phases (BCASL, installation outils, compilation). - Interruption immédiate des installations d'outils système (QProcess) via stop_signal. - Gestion de l'annulation pendant la phase de pré-compilation BCASL. - Nettoyage des processus et réactivation des contrôles GUI dès l'annulation.
1 parent 9a1b783 commit 5c96b41

3 files changed

Lines changed: 84 additions & 43 deletions

File tree

Core/Compiler/engine_runner.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,14 @@ def __init__(self, log_cb):
204204
def tr(self, fr, en): return en # Simple fallback
205205

206206
if hasattr(engine_instance, "ensure_tools_installed"):
207-
if not engine_instance.ensure_tools_installed(LogBridge(_log)):
207+
if not engine_instance.ensure_tools_installed(LogBridge(_log), stop_signal=stop_signal):
208+
if stop_signal and stop_signal():
209+
return _failure("Compilation cancelled")
208210
return _failure(f"Engine tools installation failed for '{engine_id}'")
209211

212+
if stop_signal and stop_signal():
213+
return _failure("Compilation cancelled")
214+
210215
program, args, engine_env = resolve_engine_command(engine_id, context, engine_config)
211216
except EngineRunnerError as exc:
212217
return _failure(str(exc))

Core/engine/base.py

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def required_tools(self) -> dict[str, list[str]]:
181181
"""
182182
return {"python": [], "system": []}
183183

184-
def ensure_tools_installed(self, gui) -> bool:
184+
def ensure_tools_installed(self, gui, stop_signal: Optional[Callable[[], bool]] = None) -> bool:
185185
"""
186186
Check if all required tools are installed, and install missing ones.
187187
Uses direct SysDependencyManager integration for system packages with full GUI support.
@@ -234,37 +234,47 @@ def ensure_tools_installed(self, gui) -> bool:
234234
# Use Linux package installation with progress dialog
235235
process = sys_manager.install_packages_linux(missing_system)
236236
if process:
237-
# Wait for completion with timeout
238-
if process.waitForFinished(600000): # 10 minutes
239-
if process.exitCode() == 0:
240-
log_i18n_level(
241-
gui,
242-
"success",
243-
*_tools_stage_message(
244-
"system",
245-
f"Outils système installés avec succès: {missing_system}",
246-
f"System tools installed successfully: {missing_system}",
247-
),
248-
)
249-
else:
237+
# Wait for completion with timeout, but check stop_signal
238+
timeout_total = 600000 # 10 minutes
239+
elapsed = 0
240+
interval = 500 # 0.5s
241+
while not process.waitForFinished(interval):
242+
if stop_signal and stop_signal():
243+
process.terminate()
244+
process.waitForFinished(1000)
245+
process.kill()
246+
return False
247+
elapsed += interval
248+
if elapsed >= timeout_total:
250249
log_i18n_level(
251250
gui,
252-
"error",
251+
"warning",
253252
*_tools_stage_message(
254253
"system",
255-
f"Échec installation outils système: {missing_system} (code: {process.exitCode()})",
256-
f"System tools installation failed: {missing_system} (code: {process.exitCode()})",
254+
"Timeout lors de l'installation des outils système",
255+
"Timeout during system tools installation",
257256
),
258257
)
259-
system_install_ok = False
258+
return False
259+
260+
if process.exitCode() == 0:
261+
log_i18n_level(
262+
gui,
263+
"success",
264+
*_tools_stage_message(
265+
"system",
266+
f"Outils système installés avec succès: {missing_system}",
267+
f"System tools installed successfully: {missing_system}",
268+
),
269+
)
260270
else:
261271
log_i18n_level(
262272
gui,
263-
"warning",
273+
"error",
264274
*_tools_stage_message(
265275
"system",
266-
"Timeout lors de l'installation des outils système",
267-
"Timeout during system tools installation",
276+
f"Échec installation outils système: {missing_system} (code: {process.exitCode()})",
277+
f"System tools installation failed: {missing_system} (code: {process.exitCode()})",
268278
),
269279
)
270280
system_install_ok = False
@@ -310,36 +320,46 @@ def ensure_tools_installed(self, gui) -> bool:
310320
winget_packages
311321
)
312322
if process:
313-
if process.waitForFinished(600000): # 10 minutes
314-
if process.exitCode() == 0:
323+
timeout_total = 600000 # 10 minutes
324+
elapsed = 0
325+
interval = 500 # 0.5s
326+
while not process.waitForFinished(interval):
327+
if stop_signal and stop_signal():
328+
process.terminate()
329+
process.waitForFinished(1000)
330+
process.kill()
331+
return False
332+
elapsed += interval
333+
if elapsed >= timeout_total:
315334
log_i18n_level(
316335
gui,
317-
"success",
336+
"warning",
318337
*_tools_stage_message(
319338
"system",
320-
f"Outils Windows installés: {missing_system}",
321-
f"Windows tools installed: {missing_system}",
339+
"Timeout lors de l'installation Windows",
340+
"Timeout during Windows installation",
322341
),
323342
)
324-
else:
325-
log_i18n_level(
326-
gui,
327-
"error",
328-
*_tools_stage_message(
329-
"system",
330-
f"Échec installation Windows: {missing_system}",
331-
f"Windows installation failed: {missing_system}",
332-
),
333-
)
334-
system_install_ok = False
343+
return False
344+
345+
if process.exitCode() == 0:
346+
log_i18n_level(
347+
gui,
348+
"success",
349+
*_tools_stage_message(
350+
"system",
351+
f"Outils Windows installés: {missing_system}",
352+
f"Windows tools installed: {missing_system}",
353+
),
354+
)
335355
else:
336356
log_i18n_level(
337357
gui,
338-
"warning",
358+
"error",
339359
*_tools_stage_message(
340360
"system",
341-
"Timeout lors de l'installation Windows",
342-
"Timeout during Windows installation",
361+
f"Échec installation Windows: {missing_system}",
362+
f"Windows installation failed: {missing_system}",
343363
),
344364
)
345365
system_install_ok = False
@@ -404,6 +424,9 @@ def ensure_tools_installed(self, gui) -> bool:
404424
)
405425
system_install_ok = False
406426

427+
if stop_signal and stop_signal():
428+
return False
429+
407430
# Check Python tools after the system phase, even if the system phase failed.
408431
if hasattr(gui, "venv_manager") and gui.venv_manager and python_tools:
409432
use_system = bool(getattr(gui, "use_system_python", False))
@@ -444,7 +467,7 @@ def ensure_tools_installed(self, gui) -> bool:
444467
venv_path, missing_python
445468
)
446469

447-
return system_install_ok
470+
return system_install_ok and not (stop_signal and stop_signal())
448471
except Exception as e:
449472
log_i18n_level(
450473
gui,

Ui/Gui/Dialogs/CompilerDialog.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,21 @@ def _continue_compile_all(self) -> None:
484484

485485

486486
def cancel_all_compilations(self) -> None:
487-
"""Cancel all running compilations."""
487+
"""Cancel all running compilations, including pre-compilation (BCASL)."""
488+
# 1. Handle pre-compilation (BCASL) cancellation
489+
self._cancel_requested_during_precompile = True
490+
try:
491+
from bcasl.Loader import ensure_bcasl_thread_stopped
492+
ensure_bcasl_thread_stopped(self)
493+
except Exception:
494+
pass
495+
496+
# 2. Handle main process cancellation
488497
get_main_process().cancel()
498+
499+
# 3. Enable controls
500+
self.set_controls_enabled(True)
501+
log_i18n_level(self, "info", "Annulation demandée.", "Cancellation requested.")
489502

490503

491504
def handle_stdout(self, message: str) -> None:

0 commit comments

Comments
 (0)