Skip to content

Allow proc_mesh.stop() after actor_mesh.stop() #877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions hyperactor_mesh/src/shared_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::sync::atomic::Ordering;

use async_trait::async_trait;
use dashmap::DashMap;
use futures::future::join_all;
use futures::future::try_join_all;
use preempt_rwlock::OwnedPreemptibleRwLockReadGuard;
use preempt_rwlock::PreemptibleRwLock;
Expand Down Expand Up @@ -219,6 +220,16 @@ impl SharedCellPool {
.await?;
Ok(())
}

/// Run `take` on all cells in the pool and immediately drop them or produce an error if the cell has already been taken
pub async fn discard_or_error_all(self) -> Vec<Result<(), EmptyCellError>> {
join_all(
self.map
.iter()
.map(|r| async move { r.value().discard().await }),
)
.await
}
}

/// Trait to facilitate storing `SharedCell`s of different types in a single pool.
Expand Down
4 changes: 3 additions & 1 deletion monarch_hyperactor/src/proc_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ impl PyProcMesh {
let (proc_mesh, children) = tracked_proc_mesh.into_inner();

// Now we discard all in-flight actor meshes. After this, the `ProcMesh` should be "unused".
children.discard_all().await?;
// Discarding actor meshes that have been individually stopped will result in an expected error
// which we can safely ignore
children.discard_or_error_all().await;

// Finally, take ownership of the inner proc mesh, which will allowing dropping it.
let _proc_mesh = proc_mesh.take().await?;
Expand Down
9 changes: 9 additions & 0 deletions python/tests/test_python_actors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,15 @@ async def test_actor_mesh_stop(self) -> None:
await am_2.print.call("hello 3")
await am_2.log.call("hello 4")

await pm.stop()

async def test_proc_mesh_stop_after_actor_mesh_stop(self) -> None:
pm = proc_mesh(gpus=2)
am = await pm.spawn("printer", Printer)

await cast(ActorMesh, am).stop()
await pm.stop()


class PortedActor(Actor):
@endpoint(explicit_response_port=True)
Expand Down