Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
7174Andy committed Dec 18, 2024
1 parent 3fc212d commit 0a6cc47
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
25 changes: 0 additions & 25 deletions sleap/gui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,3 @@ def select_zmq_port(zmq_context: Optional[zmq.Context] = None) -> int:
port = socket.bind_to_random_port("tcp://127.0.0.1")
socket.close()
return port


def find_free_port(port: int, zmq_context: zmq.Context):
"""Find free port to bind to.
Args:
port: The port to start searching from.
zmq_context: The ZMQ context to use.
Returns:
The free port.
"""
attempts = 0
max_attempts = 10
while not is_port_free(port=port, zmq_context=zmq_context):
if attempts >= max_attempts:
raise RuntimeError(
f"Could not find free port to display training progress after "
f"{max_attempts} attempts. Please check your network settings "
"or use the CLI `sleap-train` command."
)
port = select_zmq_port(zmq_context=self.ctx)
attempts += 1

return port
26 changes: 25 additions & 1 deletion sleap/gui/widgets/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import matplotlib.transforms as mtransforms
from qtpy import QtCore, QtWidgets

from sleap.gui.utils import find_free_port
from sleap.gui.utils import is_port_free, select_zmq_port
from sleap.gui.widgets.mpl import MplCanvas
from sleap.nn.config.training_job import TrainingJobConfig

Expand Down Expand Up @@ -785,6 +785,30 @@ def _setup_zmq(self, zmq_context: Optional[zmq.Context] = None):
self.ctx_given = zmq_context is not None
self.ctx = zmq.Context() if zmq_context is None else zmq_context

def find_free_port(port: int, zmq_context: zmq.Context):
"""Find free port to bind to.
Args:
port: The port to start searching from.
zmq_context: The ZMQ context to use.
Returns:
The free port.
"""
attempts = 0
max_attempts = 10
while not is_port_free(port=port, zmq_context=zmq_context):
if attempts >= max_attempts:
raise RuntimeError(
f"Could not find free port to display training progress after "
f"{max_attempts} attempts. Please check your network settings "
"or use the CLI `sleap-train` command."
)
port = select_zmq_port(zmq_context=self.ctx)
attempts += 1

return port

# Progress monitoring, SUBSCRIBER
self.sub = self.ctx.socket(zmq.SUB)
self.sub.subscribe("")
Expand Down

0 comments on commit 0a6cc47

Please sign in to comment.