Skip to content

Commit

Permalink
Create a new process with random name for every new module or function
Browse files Browse the repository at this point in the history
put.
  • Loading branch information
rohinb2 committed Jan 29, 2025
1 parent d81d3fa commit ba409e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
12 changes: 10 additions & 2 deletions runhouse/resources/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
client_call_wrapper,
generate_default_name,
get_module_import_info,
get_random_str,
locate_working_dir,
)

Expand Down Expand Up @@ -432,10 +433,17 @@ def to(
if not system:
raise ValueError("No system specified to send module to.")

if not process:
process = DEFAULT_PROCESS_NAME
new_name = name or self.name or self.default_name()
if self.rns_address:
new_name = f"{self._rns_folder}/{new_name}"

if process is None:
# Make this an empty dict so it'll be picked up for the process creation
process = {}

if isinstance(process, Dict):
if "name" not in process:
process["name"] = f"{new_name}_{get_random_str()}_process"
process = system.ensure_process_created(**process)
else:
system.ensure_process_created(name=process)
Expand Down
17 changes: 9 additions & 8 deletions tests/test_resources/test_clusters/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from runhouse.resources.images.image import ImageSetupStepType

from runhouse.utils import _process_env_vars
from runhouse.utils import _process_env_vars, get_random_str

import tests.test_resources.test_resource
from tests.conftest import init_args
Expand All @@ -37,7 +37,6 @@
_get_env_var_value,
friend_account,
friend_account_in_org,
get_random_str,
keep_config_keys,
org_friend_account,
set_daemon_and_cluster_status,
Expand Down Expand Up @@ -812,15 +811,17 @@ def test_put_in_default_process(self, cluster):

@pytest.mark.level("local")
@pytest.mark.clustertest
def test_fn_to_default_process(self, cluster):
def test_fn_to_no_process_specified(self, cluster):
remote_summer = rh.function(summer).to(cluster)

assert remote_summer.name in cluster.keys(process=DEFAULT_PROCESS_NAME)
assert remote_summer(3, 4) == 7
found = False
for p in cluster.list_processes():
if p.startswith(remote_summer.name):
found = True
assert remote_summer.name in cluster.keys(process=p)
break

# Test function with non-trivial imports
fn = rh.function(import_env).to(cluster)
assert fn() == "success"
assert found

@pytest.mark.level("local")
@pytest.mark.clustertest
Expand Down

0 comments on commit ba409e0

Please sign in to comment.