@@ -27,7 +27,9 @@ use monarch_hyperactor::context::PyInstance;
27
27
use monarch_hyperactor:: instance_dispatch;
28
28
use monarch_hyperactor:: proc_mesh:: PyProcMesh ;
29
29
use monarch_hyperactor:: runtime:: signal_safe_block_on;
30
+ use monarch_hyperactor:: v1:: proc_mesh:: PyProcMesh as PyProcMeshV1 ;
30
31
use pyo3:: Bound ;
32
+ use pyo3:: exceptions:: PyException ;
31
33
use pyo3:: exceptions:: PyRuntimeError ;
32
34
use pyo3:: exceptions:: PyValueError ;
33
35
use pyo3:: prelude:: * ;
@@ -264,16 +266,35 @@ impl CodeSyncMeshClient {
264
266
impl CodeSyncMeshClient {
265
267
#[ staticmethod]
266
268
#[ pyo3( signature = ( * , client, proc_mesh) ) ]
267
- fn spawn_blocking ( py : Python , client : PyInstance , proc_mesh : & PyProcMesh ) -> PyResult < Self > {
268
- let proc_mesh = proc_mesh. try_inner ( ) ?;
269
- signal_safe_block_on ( py, async move {
270
- let actor_mesh = instance_dispatch ! ( client, |cx| {
271
- proc_mesh
272
- . spawn( cx, "code_sync_manager" , & CodeSyncManagerParams { } )
273
- . await ?
274
- } ) ;
275
- Ok ( Self { actor_mesh } )
276
- } ) ?
269
+ fn spawn_blocking (
270
+ py : Python ,
271
+ client : PyInstance ,
272
+ proc_mesh : & Bound < ' _ , PyAny > ,
273
+ ) -> PyResult < Self > {
274
+ if let Ok ( v0) = proc_mesh. downcast :: < PyProcMesh > ( ) {
275
+ let proc_mesh = v0. borrow ( ) . try_inner ( ) ?;
276
+ signal_safe_block_on ( py, async move {
277
+ let actor_mesh = instance_dispatch ! ( client, |cx| {
278
+ proc_mesh
279
+ . spawn( cx, "code_sync_manager" , & CodeSyncManagerParams { } )
280
+ . await ?
281
+ } ) ;
282
+ Ok ( Self { actor_mesh } )
283
+ } ) ?
284
+ } else {
285
+ let proc_mesh = proc_mesh. downcast :: < PyProcMeshV1 > ( ) ?. borrow ( ) . mesh_ref ( ) ?;
286
+ signal_safe_block_on ( py, async move {
287
+ let actor_mesh = instance_dispatch ! ( client, |cx| {
288
+ proc_mesh
289
+ . spawn_service( cx, "code_sync_manager" , & CodeSyncManagerParams { } )
290
+ . await
291
+ . map_err( |err| PyException :: new_err( err. to_string( ) ) ) ?
292
+ } ) ;
293
+ Ok ( Self {
294
+ actor_mesh : SharedCell :: from ( RootActorMesh :: from ( actor_mesh) ) ,
295
+ } )
296
+ } ) ?
297
+ }
277
298
}
278
299
279
300
#[ pyo3( signature = ( * , local, remote, method = PyCodeSyncMethod :: Rsync { } , auto_reload = false ) ) ]
0 commit comments