diff --git a/RELEASE.md b/RELEASE.md index 295184a21..1cbfe3b8f 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -5,6 +5,15 @@ Please follow the established format: - Use present tense (e.g. 'Add new feature') - Include the ID number for the related PR (or PRs) in parentheses --> +# Upcoming Release + +## Major features and improvements + +## Bug fixes and other changes + +- Fix `%run_viz` using old process in jupyter notebook. (#2267) + +## Community contributions # Release 10.2.0 diff --git a/docs/source/publish_and_share_kedro_viz_on_gcp.md b/docs/source/publish_and_share_kedro_viz_on_gcp.md index d054bbe41..1677af637 100644 --- a/docs/source/publish_and_share_kedro_viz_on_gcp.md +++ b/docs/source/publish_and_share_kedro_viz_on_gcp.md @@ -116,4 +116,4 @@ You can control who can view your visualisation using [IAM permissions and ACLs] Kedro-Viz does not handle billing. You pay for storing objects on your Google Cloud Storage. The amount you pay depends on the amount of data stored, data processing and network usage. Additionally you may be charged for using cloud load balancing. -See the official [Google Cloud Storage Billing](https://cloud.google.com/storage/pricing) and [Google Cloud Load Balancer Billing](https://cloud.google.com/vpc/network-pricing#lb) for more information. +See the official [Google Cloud Storage Billing](https://cloud.google.com/storage/pricing) and [Google Cloud Load Balancer Billing](https://cloud.google.com/vpc/network-pricing) for more information. diff --git a/package/kedro_viz/launchers/jupyter.py b/package/kedro_viz/launchers/jupyter.py index cd39610ab..97a4c68fc 100644 --- a/package/kedro_viz/launchers/jupyter.py +++ b/package/kedro_viz/launchers/jupyter.py @@ -7,8 +7,6 @@ import multiprocessing import os import shlex -import socket -from contextlib import closing from typing import Any, Dict import IPython @@ -17,7 +15,7 @@ from watchfiles import run_process from kedro_viz.autoreload_file_filter import AutoreloadFileFilter -from kedro_viz.launchers.utils import _check_viz_up, _wait_for +from kedro_viz.launchers.utils import _check_viz_up, _find_available_port, _wait_for from kedro_viz.server import DEFAULT_HOST, DEFAULT_PORT, run_server _VIZ_PROCESSES: Dict[str, int] = {} @@ -26,25 +24,6 @@ logger = logging.getLogger(__name__) -def _allocate_port(host: str, start_at: int, end_at: int = 65535) -> int: - acceptable_ports = range(start_at, end_at + 1) - - viz_ports = _VIZ_PROCESSES.keys() & set(acceptable_ports) - if viz_ports: # reuse one of already allocated ports - return sorted(viz_ports)[0] - - socket.setdefaulttimeout(2.0) # seconds - for port in acceptable_ports: # iterate through all acceptable ports - with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock: - if sock.connect_ex((host, port)) != 0: # port is available - return port - - raise ValueError( - "Cannot allocate an open TCP port for Kedro-Viz in a range " - f"from {start_at} to {end_at}" - ) - - def _is_databricks() -> bool: return "DATABRICKS_RUNTIME_VERSION" in os.environ @@ -120,7 +99,7 @@ def run_viz(args: str = "", local_ns: Dict[str, Any] = None) -> None: params = arg_dict.get("params", "") # Allocate port - port = _allocate_port(host, start_at=port) + port = _find_available_port(host, port, max_attempts=10) # Terminate existing process if needed if port in _VIZ_PROCESSES and _VIZ_PROCESSES[port].is_alive(): diff --git a/package/kedro_viz/launchers/utils.py b/package/kedro_viz/launchers/utils.py index 50f8e6e84..bdbc49c38 100644 --- a/package/kedro_viz/launchers/utils.py +++ b/package/kedro_viz/launchers/utils.py @@ -90,6 +90,14 @@ def _is_port_in_use(host: str, port: int): def _find_available_port(host: str, start_port: int, max_attempts: int = 5) -> int: max_port = start_port + max_attempts - 1 port = start_port + + # Sanity check to not collide with system ports + if port > 49151: + raise ValueError( + "Cannot allocate an open TCP port for Kedro-Viz in a range " + f"from {start_port} to {max_port}" + ) + while port <= max_port: if not _is_port_in_use(host, port): return port