(self, start_funcs=[], start_args=[])
| 11 | self.processes = [] |
| 12 | |
| 13 | def start_submodule_processes(self, start_funcs=[], start_args=[]): |
| 14 | assert len(start_funcs) == len(start_args) |
| 15 | pipe_readers = [] |
| 16 | processes = [] |
| 17 | |
| 18 | for start_func, start_arg in zip(start_funcs, start_args): |
| 19 | pipe_reader, pipe_writer = mp.Pipe(duplex=False) |
| 20 | process = mp.Process( |
| 21 | target=start_func, |
| 22 | args=start_arg + (pipe_writer,), |
| 23 | ) |
| 24 | process.start() |
| 25 | pipe_readers.append(pipe_reader) |
| 26 | processes.append(process) |
| 27 | |
| 28 | # Wait for all processes to initialize |
| 29 | for index, pipe_reader in enumerate(pipe_readers): |
| 30 | init_state = pipe_reader.recv() |
| 31 | if init_state != "init ok": |
| 32 | logger.error(f"init func {start_funcs[index].__name__} : {str(init_state)}") |
| 33 | for proc in processes: |
| 34 | proc.kill() |
| 35 | sys.exit(1) |
| 36 | else: |
| 37 | logger.info(f"init func {start_funcs[index].__name__} : {str(init_state)}") |
| 38 | |
| 39 | assert all([proc.is_alive() for proc in processes]) |
| 40 | self.processes.extend(processes) |
| 41 | return |
| 42 | |
| 43 | def terminate_all_processes(self): |
| 44 | from lightllm.utils.envs_utils import get_env_start_args |
no test coverage detected