From 3320bd3e6822d7fd7c2b916fc777451b56b804fb Mon Sep 17 00:00:00 2001 From: plan Date: Sun, 14 Jul 2024 21:11:48 +0800 Subject: [PATCH] Fix address.split for ipv6 Because ipv6 ip has multiple ':' --- python/xoscar/backends/communication/socket.py | 4 ++-- python/xoscar/backends/communication/ucx.py | 4 ++-- python/xoscar/backends/indigen/pool.py | 2 +- python/xoscar/collective/core.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/python/xoscar/backends/communication/socket.py b/python/xoscar/backends/communication/socket.py index 5c2c5a26..4fa7deba 100644 --- a/python/xoscar/backends/communication/socket.py +++ b/python/xoscar/backends/communication/socket.py @@ -207,7 +207,7 @@ async def create(config: Dict) -> "Server": config = config.copy() if "address" in config: address = config.pop("address") - host, port = address.split(":", 1) + host, port = address.rsplit(":", 1) port = int(port) else: host = config.pop("host") @@ -250,7 +250,7 @@ class SocketClient(Client): async def connect( dest_address: str, local_address: str | None = None, **kwargs ) -> "Client": - host, port_str = dest_address.split(":", 1) + host, port_str = dest_address.rsplit(":", 1) port = int(port_str) (reader, writer) = await asyncio.open_connection(host=host, port=port, **kwargs) channel = SocketChannel( diff --git a/python/xoscar/backends/communication/ucx.py b/python/xoscar/backends/communication/ucx.py index cc66f7fb..360683d6 100644 --- a/python/xoscar/backends/communication/ucx.py +++ b/python/xoscar/backends/communication/ucx.py @@ -401,7 +401,7 @@ async def create(config: Dict) -> "Server": prefix = f"{UCXServer.scheme}://" if address.startswith(prefix): address = address[len(prefix) :] - host, port = address.split(":", 1) + host, port = address.rsplit(":", 1) port = int(port) else: host = config.pop("host") @@ -498,7 +498,7 @@ async def connect( prefix = f"{UCXClient.scheme}://" if dest_address.startswith(prefix): dest_address = dest_address[len(prefix) :] - host, port_str = dest_address.split(":", 1) + host, port_str = dest_address.rsplit(":", 1) port = int(port_str) kwargs = kwargs.copy() ucx_config = kwargs.pop("config", dict()).get("ucx", dict()) diff --git a/python/xoscar/backends/indigen/pool.py b/python/xoscar/backends/indigen/pool.py index 045c77a7..183c676c 100644 --- a/python/xoscar/backends/indigen/pool.py +++ b/python/xoscar/backends/indigen/pool.py @@ -132,7 +132,7 @@ def get_external_addresses( """Get external address for every process""" assert n_process is not None if ":" in address: - host, port_str = address.split(":", 1) + host, port_str = address.rsplit(":", 1) port = int(port_str) if ports: if len(ports) != n_process: diff --git a/python/xoscar/collective/core.py b/python/xoscar/collective/core.py index a2f50782..d5e7d962 100644 --- a/python/xoscar/collective/core.py +++ b/python/xoscar/collective/core.py @@ -95,7 +95,7 @@ def backend(self) -> str: return self._backend def _get_ip(self) -> str: - return self.address.split(":")[0] + return self.address.rsplit(":", 1)[0] def _process_group_name(self, ranks: List[int]) -> str: return hashlib.sha1(