Skip to content

Commit a42dbe3

Browse files
committed
Généralisation de la boucle d'événements locale pour les threads d'arrière-plan (GUI & CLI)
1 parent 83262d8 commit a42dbe3

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

Core/Venv_Manager/Manager.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,18 @@ def ensure_tools_installed(self, venv_root: str, tools: list[str]) -> None:
485485
)
486486
self._call_ui("update_progress_progress", "tools_check", 0, len(tools))
487487

488-
# In CLI mode without a global event loop, we might need a local one
489-
is_cli = getattr(self.parent, "verbose", False) or os.environ.get("PYCOMPILER_CLI") == "1"
488+
# We need a local event loop if we are in a background thread or CLI mode
489+
# to process QProcess signals and QTimer events.
490+
from PySide6.QtCore import QCoreApplication, QEventLoop, QThread
491+
492+
must_wait = (
493+
getattr(self.parent, "verbose", False) or
494+
os.environ.get("PYCOMPILER_CLI") == "1" or
495+
(QCoreApplication.instance() and QThread.currentThread() != QCoreApplication.instance().thread())
496+
)
497+
490498
loop = None
491-
if is_cli:
492-
from PySide6.QtCore import QCoreApplication, QEventLoop
499+
if must_wait:
493500
if not QCoreApplication.instance():
494501
self._app_ref = QCoreApplication([]) # Keep alive
495502

@@ -541,18 +548,20 @@ def ensure_tools_installed_system(self, tools: list[str]) -> None:
541548
self._bind_cancel_for_progress(
542549
"tools_check", "verification des outils systeme"
543550
)
544-
self._call_ui(
545-
"update_progress_message",
546-
"tools_check",
547-
f"Verification de {tools[0]}...",
548-
)
551+
self._call_ui("update_progress_message", "tools_check", f"Verification de {tools[0]}...")
549552
self._call_ui("update_progress_progress", "tools_check", 0, len(tools))
550553

551-
# In CLI mode without a global event loop, we might need a local one
552-
is_cli = getattr(self.parent, "verbose", False) or os.environ.get("PYCOMPILER_CLI") == "1"
554+
# We need a local event loop if we are in a background thread or CLI mode
555+
from PySide6.QtCore import QCoreApplication, QEventLoop, QThread
556+
557+
must_wait = (
558+
getattr(self.parent, "verbose", False) or
559+
os.environ.get("PYCOMPILER_CLI") == "1" or
560+
(QCoreApplication.instance() and QThread.currentThread() != QCoreApplication.instance().thread())
561+
)
562+
553563
loop = None
554-
if is_cli:
555-
from PySide6.QtCore import QCoreApplication, QEventLoop
564+
if must_wait:
556565
if not QCoreApplication.instance():
557566
self._app_ref = QCoreApplication([]) # Keep alive
558567

0 commit comments

Comments
 (0)