Skip to content

Commit

Permalink
Add animated spinners to long running operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohinb2 committed May 22, 2024
1 parent 2c5d53a commit 9079559
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 193 deletions.
13 changes: 10 additions & 3 deletions runhouse/resources/hardware/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from runhouse.resources.resource import Resource

from runhouse.servers.http import HTTPClient
from runhouse.utils import alive_bar_spinner_only, success_emoji

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -651,9 +652,15 @@ def check_server(self, restart_server=True):
if not self.client:
try:
self.connect_server_client()
logger.debug(f"Checking server {self.name}")
self.client.check_server()
logger.info(f"Server {self.name} is up.")
with alive_bar_spinner_only(
title=f"Checking Runhouse server on cluster {self.name} is up..."
) as bar:
self.client.check_server()
bar.title(
success_emoji(
f"Confirmed Runhouse server on cluster {self.name} is up"
)
)
except (
requests.exceptions.ConnectionError,
requests.exceptions.ReadTimeout,
Expand Down
72 changes: 38 additions & 34 deletions runhouse/resources/hardware/sky_ssh_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
SSHCommandRunner,
SshMode,
)

from runhouse.utils import alive_bar_spinner_only, success_emoji

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -90,7 +90,7 @@ def _ssh_base_command(
local, remote = fwd, fwd
else:
local, remote = fwd
logger.info(f"Forwarding port {local} to port {remote} on localhost.")
logger.debug(f"Forwarding port {local} to port {remote} on localhost.")
ssh += ["-L", f"{local}:localhost:{remote}"]
if self._docker_ssh_proxy_command is not None:
docker_ssh_proxy_command = self._docker_ssh_proxy_command(ssh)
Expand Down Expand Up @@ -472,39 +472,43 @@ def ssh_tunnel(
)
return tunnel

while is_port_in_use(local_port):
if num_ports_to_try < 0:
raise Exception(
f"Failed to create find open port after {num_ports_to_try} attempts"
)
with alive_bar_spinner_only(title="Creating ssh tunnel to remote host...") as bar:
while is_port_in_use(local_port):
if num_ports_to_try < 0:
raise Exception(
f"Failed to create find open port after {num_ports_to_try} attempts"
)

logger.info(f"Port {local_port} is already in use. Trying next port.")
local_port += 1
num_ports_to_try -= 1

# Start a tunnel using self.run in a thread, instead of ssh_tunnel
ssh_credentials = copy.copy(ssh_creds)

# Host could be a proxy specified in credentials or is the provided address
host = ssh_credentials.pop("ssh_host", address)
ssh_control_name = ssh_credentials.pop("ssh_control_name", f"{address}:{ssh_port}")

runner = SkySSHRunner(
ip=host,
ssh_user=ssh_creds.get("ssh_user"),
ssh_private_key=ssh_creds.get("ssh_private_key"),
ssh_proxy_command=ssh_creds.get("ssh_proxy_command"),
ssh_control_name=ssh_control_name,
port=ssh_port,
)
runner.tunnel(local_port, remote_port)

logger.debug(
f"Successfully bound "
f"{LOCALHOST}:{remote_port} via ssh port {ssh_port} "
f"on remote server {address} "
f"to {LOCALHOST}:{local_port} on local machine."
)
logger.info(f"Port {local_port} is already in use. Trying next port.")
local_port += 1
num_ports_to_try -= 1

# Start a tunnel using self.run in a thread, instead of ssh_tunnel
ssh_credentials = copy.copy(ssh_creds)

# Host could be a proxy specified in credentials or is the provided address
host = ssh_credentials.pop("ssh_host", address)
ssh_control_name = ssh_credentials.pop(
"ssh_control_name", f"{address}:{ssh_port}"
)

runner = SkySSHRunner(
ip=host,
ssh_user=ssh_creds.get("ssh_user"),
ssh_private_key=ssh_creds.get("ssh_private_key"),
ssh_proxy_command=ssh_creds.get("ssh_proxy_command"),
ssh_control_name=ssh_control_name,
port=ssh_port,
)
runner.tunnel(local_port, remote_port)

logger.info(
f"Successfully bound "
f"{LOCALHOST}:{remote_port} via ssh port {ssh_port} "
f"on remote server {address} "
f"to {LOCALHOST}:{local_port} on local machine."
)
bar.title(success_emoji(f"SSH tunnel to {address} created successfully "))

cache_existing_sky_ssh_runner(address, ssh_port, runner)
return runner
14 changes: 10 additions & 4 deletions runhouse/resources/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from runhouse.rns.utils.names import _generate_default_name
from runhouse.servers.http import HTTPClient
from runhouse.servers.http.http_utils import CallParams
from runhouse.utils import alive_bar_spinner_only, success_emoji

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -488,10 +489,15 @@ def to(
for attr, val in self.__dict__.items()
if attr not in excluded_state_keys
}
logger.info(
f"Sending module {new_module.name} of type {type(new_module)} to {system.name or 'local Runhouse daemon'}"
)
system.put_resource(new_module, state, dryrun=True)
with alive_bar_spinner_only(
title=f"Sending module {new_module.name} of type {type(new_module)} to {system.name or 'local Runhouse daemon'}"
) as bar:
system.put_resource(new_module, state, dryrun=True)
bar.title(
success_emoji(
f"Sending module {new_module.name} of type {type(new_module)} to {system.name or 'local Runhouse daemon'}"
)
)

return new_module

Expand Down
16 changes: 12 additions & 4 deletions runhouse/resources/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from runhouse.resources.folders import Folder, folder
from runhouse.resources.hardware.utils import _get_cluster_from
from runhouse.resources.resource import Resource
from runhouse.utils import alive_bar_spinner_only, success_emoji

INSTALL_METHODS = {"local", "reqs", "pip", "conda"}

Expand Down Expand Up @@ -356,10 +357,17 @@ def to(
# If we're on the target system, just make sure the package is in the Python path
sys.path.append(self.install_target.local_path)
return self
logger.info(
f"Copying package from {self.install_target.fsspec_url} to: {getattr(system, 'name', system)}"
)
new_folder = self.install_target._to_cluster(system, path=path, mount=mount)
with alive_bar_spinner_only(
title=f"Copying package from {self.install_target.fsspec_url} to: {getattr(system, 'name', system)}"
) as bar:
new_folder = self.install_target._to_cluster(
system, path=path, mount=mount
)
bar.title(
success_emoji(
f"Package copied to: {getattr(system, 'name', system)}"
)
)
else: # to fs
new_folder = self.install_target.to(system, path=path)
new_folder.system = system
Expand Down

0 comments on commit 9079559

Please sign in to comment.