mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Find available port when starting backend plugin
CURA-11067
This commit is contained in:
parent
26e7995588
commit
d4449c680f
2 changed files with 11 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
|||
# Copyright (c) 2023 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
import socket
|
||||
import subprocess
|
||||
from typing import Optional, List
|
||||
|
||||
|
@ -42,6 +43,15 @@ class BackendPlugin(AdditionalSettingDefinitionsAppender, PluginObject):
|
|||
def getAddress(self) -> str:
|
||||
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]:
|
||||
"""
|
||||
Validate the plugin command and add the port parameter if it is missing.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue