Addon Manager: Clean up thread termination

This commit is contained in:
Chris Hennes
2022-01-08 22:30:05 -06:00
parent a34aa34b0b
commit 47ca151c81
2 changed files with 13 additions and 14 deletions

View File

@@ -413,6 +413,7 @@ class CommandAddonManager:
thread = getattr(self, worker)
if thread:
if not thread.isFinished():
thread.blockSignals(True)
thread.requestInterruption()
worker_killed = True
oktoclose = False
@@ -974,9 +975,7 @@ class CommandAddonManager:
self.install(repo)
def cancel_dependency_installation(self) -> None:
self.dependency_installation_worker.finished.disconnect(
lambda: self.install(repo)
)
self.dependency_installation_worker.blockSignals(True)
self.dependency_installation_worker.requestInterruption()
self.dependency_installation_dialog.hide()
@@ -1053,6 +1052,7 @@ class CommandAddonManager:
and self.update_check_single_worker
):
if self.update_check_single_worker.isRunning():
self.update_check_single_worker.blockSignals(True)
self.update_check_single_worker.requestInterrupt()
self.update_check_single_worker.wait()

View File

@@ -678,11 +678,12 @@ class CacheMacroCode(QtCore.QThread):
while True:
if current_thread.isInterruptionRequested():
for worker in self.workers:
worker.blockSignals(True)
worker.requestInterruption()
worker.wait(100)
if not worker.isFinished():
# Kill it
worker.terminate()
if not worker.wait(100):
FreeCAD.PrintWarning(
f"Addon Manager: a worker process failed to halt ({worker.macro.name})"
)
return
# Ensure our signals propagate out by running an internal thread-local event loop
QtCore.QCoreApplication.processEvents()
@@ -698,7 +699,6 @@ class CacheMacroCode(QtCore.QThread):
FreeCAD.Console.PrintError(
f"Addon Manager: a worker process failed to complete while fetching {worker.macro.name}\n"
)
worker.terminate()
self.repo_queue.join()
for terminator in self.terminators:
@@ -758,15 +758,13 @@ class CacheMacroCode(QtCore.QThread):
)
+ "\n"
)
worker.blockSignals(True)
worker.requestInterruption()
worker.wait(100)
if worker.isRunning():
worker.terminate()
worker.wait(50)
if worker.isRunning():
FreeCAD.Console.PrintError(
f"Failed to kill process for macro {macro_name}!\n"
)
FreeCAD.Console.PrintError(
f"Failed to kill process for macro {macro_name}!\n"
)
with self.lock:
self.failed.append(macro_name)
@@ -1591,6 +1589,7 @@ class UpdateAllWorker(QtCore.QThread):
while not self.repo_queue.empty():
if current_thread.isInterruptionRequested():
for worker in workers:
worker.blockSignals(True)
worker.requestInterruption()
worker.wait()
return