@@ -566,24 +566,27 @@ def address(self):
566566 return f"{ self .prefix } { self .ip } :{ self .port } "
567567
568568 async def start (self ):
569- async def serve_forever (client_ep ):
570- ucx = self .comm_class (
569+ async def serve_forever (client_ep , * , selfref ):
570+ ucx = selfref () .comm_class (
571571 client_ep ,
572- local_addr = self .address ,
573- peer_addr = self .address ,
574- deserialize = self .deserialize ,
572+ local_addr = selfref () .address ,
573+ peer_addr = selfref () .address ,
574+ deserialize = selfref () .deserialize ,
575575 )
576- ucx .allow_offload = self .allow_offload
576+ ucx .allow_offload = selfref () .allow_offload
577577 try :
578- await self .on_connection (ucx )
578+ await selfref () .on_connection (ucx )
579579 except CommClosedError :
580580 logger .debug ("Connection closed before handshake completed" )
581581 return
582- if self .comm_handler :
583- await self .comm_handler (ucx )
582+ if selfref () .comm_handler :
583+ await selfref () .comm_handler (ucx )
584584
585585 init_once ()
586- self .ucxx_server = ucxx .create_listener (serve_forever , port = self ._input_port )
586+ self .ucxx_server = ucxx .create_listener (
587+ functools .partial (serve_forever , selfref = weakref .ref (self )),
588+ port = self ._input_port ,
589+ )
587590
588591 def stop (self ):
589592 self .ucxx_server = None
0 commit comments