Engine-plugins wouldn't always close.

... because the code to terminate them wasn't always called. Especially annoying on Windows, since the sub-program could aparently become a zomboid after termination of the main one(s).

I guess this is still part of the still open CURA-10475 'branch' in a way? There is no other ticket that fits at the moment.
This commit is contained in:
Remco Burema 2023-08-29 22:46:35 +02:00
parent 70e858ecb6
commit 015e635213

View file

@ -200,14 +200,23 @@ class CuraEngineBackend(QObject, Backend):
It assigns unique ports to each plugin to avoid conflicts. It assigns unique ports to each plugin to avoid conflicts.
:return: :return:
""" """
self.stopPlugins()
backend_plugins = CuraApplication.getInstance().getBackendPlugins()
for backend_plugin in backend_plugins:
# Set the port to prevent plugins from using the same one.
if backend_plugin.getPort() < 1:
backend_plugin.setPort(self._last_backend_plugin_port)
self._last_backend_plugin_port += 1
backend_plugin.start()
def stopPlugins(self) -> None:
"""
Ensure that all backend plugins will be terminated.
"""
backend_plugins = CuraApplication.getInstance().getBackendPlugins() backend_plugins = CuraApplication.getInstance().getBackendPlugins()
for backend_plugin in backend_plugins: for backend_plugin in backend_plugins:
if backend_plugin.isRunning(): if backend_plugin.isRunning():
backend_plugin.stop() backend_plugin.stop()
# Set the port to prevent plugins from using the same one.
backend_plugin.setPort(self._last_backend_plugin_port)
self._last_backend_plugin_port += 1
backend_plugin.start()
def _resetLastSliceTimeStats(self) -> None: def _resetLastSliceTimeStats(self) -> None:
self._time_start_process = None self._time_start_process = None
@ -396,6 +405,8 @@ class CuraEngineBackend(QObject, Backend):
if self._start_slice_job is not None: if self._start_slice_job is not None:
self._start_slice_job.cancel() self._start_slice_job.cancel()
self.stopPlugins()
self.slicingCancelled.emit() self.slicingCancelled.emit()
self.processingProgress.emit(0) self.processingProgress.emit(0)
Logger.log("d", "Attempting to kill the engine process") Logger.log("d", "Attempting to kill the engine process")
@ -795,6 +806,8 @@ class CuraEngineBackend(QObject, Backend):
:param message: The protobuf message signalling that slicing is finished. :param message: The protobuf message signalling that slicing is finished.
""" """
self.stopPlugins()
self.setState(BackendState.Done) self.setState(BackendState.Done)
self.processingProgress.emit(1.0) self.processingProgress.emit(1.0)
self._time_end_slice = time() self._time_end_slice = time()
@ -1009,7 +1022,6 @@ class CuraEngineBackend(QObject, Backend):
We should reset our state and start listening for new connections. We should reset our state and start listening for new connections.
""" """
if not self._restart: if not self._restart:
if self._process: # type: ignore if self._process: # type: ignore
return_code = self._process.wait() return_code = self._process.wait()
@ -1020,6 +1032,7 @@ class CuraEngineBackend(QObject, Backend):
self.stopSlicing() self.stopSlicing()
else: else:
Logger.log("d", "Backend finished slicing. Resetting process and socket.") Logger.log("d", "Backend finished slicing. Resetting process and socket.")
self.stopPlugins()
self._process = None # type: ignore self._process = None # type: ignore
def _reportBackendError(self, _message_id: str, _action_id: str) -> None: def _reportBackendError(self, _message_id: str, _action_id: str) -> None: