mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 11:49:01 +08:00
Merge pull request #16772 from Ultimaker/CURA-11067-backend-plugin-find-available-port
Find available port when starting backend plugin
This commit is contained in:
commit
aacffbc0d5
@ -1,5 +1,6 @@
|
|||||||
# Copyright (c) 2023 Ultimaker B.V.
|
# Copyright (c) 2023 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
|
|
||||||
@ -42,6 +43,15 @@ class BackendPlugin(AdditionalSettingDefinitionsAppender, PluginObject):
|
|||||||
def getAddress(self) -> str:
|
def getAddress(self) -> str:
|
||||||
return self._plugin_address
|
return self._plugin_address
|
||||||
|
|
||||||
|
def setAvailablePort(self) -> None:
|
||||||
|
"""
|
||||||
|
Sets the port to a random available port.
|
||||||
|
"""
|
||||||
|
sock = socket.socket()
|
||||||
|
sock.bind((self.getAddress(), 0))
|
||||||
|
port = sock.getsockname()[1]
|
||||||
|
self.setPort(port)
|
||||||
|
|
||||||
def _validatePluginCommand(self) -> list[str]:
|
def _validatePluginCommand(self) -> list[str]:
|
||||||
"""
|
"""
|
||||||
Validate the plugin command and add the port parameter if it is missing.
|
Validate the plugin command and add the port parameter if it is missing.
|
||||||
|
@ -83,7 +83,6 @@ class CuraEngineBackend(QObject, Backend):
|
|||||||
os.path.join(CuraApplication.getInstallPrefix(), "bin"),
|
os.path.join(CuraApplication.getInstallPrefix(), "bin"),
|
||||||
os.path.dirname(os.path.abspath(sys.executable)),
|
os.path.dirname(os.path.abspath(sys.executable)),
|
||||||
]
|
]
|
||||||
self._last_backend_plugin_port = self._port + 1000
|
|
||||||
for path in search_path:
|
for path in search_path:
|
||||||
engine_path = os.path.join(path, executable_name)
|
engine_path = os.path.join(path, executable_name)
|
||||||
if os.path.isfile(engine_path):
|
if os.path.isfile(engine_path):
|
||||||
@ -205,8 +204,7 @@ class CuraEngineBackend(QObject, Backend):
|
|||||||
for backend_plugin in backend_plugins:
|
for backend_plugin in backend_plugins:
|
||||||
# Set the port to prevent plugins from using the same one.
|
# Set the port to prevent plugins from using the same one.
|
||||||
if backend_plugin.getPort() < 1:
|
if backend_plugin.getPort() < 1:
|
||||||
backend_plugin.setPort(self._last_backend_plugin_port)
|
backend_plugin.setAvailablePort()
|
||||||
self._last_backend_plugin_port += 1
|
|
||||||
backend_plugin.start()
|
backend_plugin.start()
|
||||||
|
|
||||||
def stopPlugins(self) -> None:
|
def stopPlugins(self) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user