@@ -1528,15 +1528,24 @@ async def stop(self) -> None:
15281528 if is_running :
15291529 if runtime_shutdown_completed :
15301530 try :
1531- self ._cli_process .wait (timeout = _RUNTIME_SHUTDOWN_TIMEOUT_SECONDS )
1531+ await asyncio .to_thread (
1532+ self ._cli_process .wait ,
1533+ timeout = _RUNTIME_SHUTDOWN_TIMEOUT_SECONDS ,
1534+ )
15321535 except subprocess .TimeoutExpired :
15331536 self ._cli_process .terminate ()
15341537 try :
1535- self ._cli_process .wait (timeout = _CLI_PROCESS_EXIT_TIMEOUT_SECONDS )
1538+ await asyncio .to_thread (
1539+ self ._cli_process .wait ,
1540+ timeout = _CLI_PROCESS_EXIT_TIMEOUT_SECONDS ,
1541+ )
15361542 except subprocess .TimeoutExpired :
15371543 self ._cli_process .kill ()
15381544 try :
1539- self ._cli_process .wait (timeout = _CLI_PROCESS_EXIT_TIMEOUT_SECONDS )
1545+ await asyncio .to_thread (
1546+ self ._cli_process .wait ,
1547+ timeout = _CLI_PROCESS_EXIT_TIMEOUT_SECONDS ,
1548+ )
15401549 except subprocess .TimeoutExpired as e :
15411550 errors .append (
15421551 StopError (
@@ -1549,17 +1558,22 @@ async def stop(self) -> None:
15491558 else :
15501559 self ._cli_process .terminate ()
15511560 try :
1552- self ._cli_process .wait (timeout = _CLI_PROCESS_EXIT_TIMEOUT_SECONDS )
1561+ await asyncio .to_thread (
1562+ self ._cli_process .wait ,
1563+ timeout = _CLI_PROCESS_EXIT_TIMEOUT_SECONDS ,
1564+ )
15531565 except subprocess .TimeoutExpired :
15541566 self ._cli_process .kill ()
15551567 try :
1556- self ._cli_process .wait (timeout = _CLI_PROCESS_EXIT_TIMEOUT_SECONDS )
1568+ await asyncio .to_thread (
1569+ self ._cli_process .wait ,
1570+ timeout = _CLI_PROCESS_EXIT_TIMEOUT_SECONDS ,
1571+ )
15571572 except subprocess .TimeoutExpired as e :
15581573 errors .append (
15591574 StopError (
15601575 message = (
1561- "Timed out waiting for CLI process to exit after kill: "
1562- f"{ e } "
1576+ f"Timed out waiting for CLI process to exit after kill: { e } "
15631577 )
15641578 )
15651579 )
@@ -1602,6 +1616,8 @@ async def force_stop(self) -> None:
16021616 if self ._is_external_server :
16031617 if self ._process is not None :
16041618 self ._process .terminate () # closes the TCP socket
1619+ self ._process = None
1620+ self ._cli_process = None
16051621 else :
16061622 if self ._process is not None and self ._process is not self ._cli_process :
16071623 self ._process .terminate ()
0 commit comments