已合并
[Fix] static kernel install path decoupled from static_kernel_compile_outputs #3439
rich创建于 7月23日
[Fix] static kernel install path decoupled from static_kernel_compile_outputs #3439
已合并
共 2 个文件变更+17-13
| @@ -67,7 +67,8 @@ | |||
| 67 | 假设产物路径为`/path/test`,目录结构如下,其中`{timestamp}`为时间戳、`{pid}`表示运行的进程号。 | 67 | 假设产物路径为`/path/test`,目录结构如下,其中`{timestamp}`为时间戳、`{pid}`表示运行的进程号。 |
| 68 | > [!NOTE]说明 | 68 | > [!NOTE]说明 |
| 69 | > | 69 | > |
| 70 | ->- 当静态Kernel编译进程异常退出时,请根据终端界面提示信息中的uninstall.sh脚本路径执行uninstall.sh脚本对静态Kernel包进行卸载。 | 70 | +>- 用户需要对进程工作目录具有读、写和执行权限。 |
| 71 | +>- 静态编译除下方产物外还会生成临时产物,正常流程自动清理。进程异常退出时可手动清理:若终端界面有提示静态Kernel的`uninstall.sh`脚本则执行此脚本;若工作目录存在`static_kernel_install`目录,则清理对应`{timestamp}_{pid}`子目录。 | ||
| 71 | 72 | ||
| 72 | ```txt | 73 | ```txt |
| 73 | static_kernel_compile_outputs // 固定的产物文件名 | 74 | static_kernel_compile_outputs // 固定的产物文件名 |
| @@ -34,7 +34,7 @@ try: | |||
| 34 | except ImportError: | 34 | except ImportError: |
| 35 | _use_process_isolation = False | 35 | _use_process_isolation = False |
| 36 | _current_install_path = None | 36 | _current_install_path = None |
| 37 | -_owns_install_path = False | 37 | +_owns_install_path = None |
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | def _format_value(value) -> str: | 40 | def _format_value(value) -> str: |
| @@ -660,23 +660,26 @@ def _is_multicard_env_valid() -> bool: | |||
| 660 | return True | 660 | return True |
| 661 | 661 | ||
| 662 | 662 | ||
| 663 | -def _get_or_create_install_path(result_root: Path) -> Path: | 663 | +def _get_or_create_install_path() -> Path: |
| 664 | """ | 664 | """ |
| 665 | Get or create a per-process install directory for static kernel run packages. | 665 | Get or create a per-process install directory for static kernel run packages. |
| 666 | 666 | ||
| 667 | In process isolation mode, each process installs its kernels into a unique | 667 | In process isolation mode, each process installs its kernels into a unique |
| 668 | - directory (under <result_root.parent>/install/<timestamp>_<pid>) to avoid | 668 | + directory (under <cwd>/static_kernel_install/<timestamp>_<pid>) to avoid |
| 669 | - conflicts with other processes. The path is created on first call and cached | 669 | + conflicts with other processes. The path is created on first call and cached globally. |
| 670 | - globally; subsequent calls return the cached path and ignore result_root. | ||
| 671 | """ | 670 | """ |
| 672 | global _current_install_path, _owns_install_path | 671 | global _current_install_path, _owns_install_path |
| 673 | if _current_install_path is None: | 672 | if _current_install_path is None: |
| 674 | timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S%f') | 673 | timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S%f') |
| 675 | pid = os.getpid() | 674 | pid = os.getpid() |
| 676 | - base_dir = result_root.parent / "install" | 675 | + base_dir = Path.cwd().resolve() / "static_kernel_install" |
| 677 | - _current_install_path = base_dir / f"{timestamp}_{pid}" | 676 | + install_path = base_dir / f"{timestamp}_{pid}" |
| 678 | - _current_install_path.mkdir(parents=True, exist_ok=True) | 677 | + try: |
| 679 | - _owns_install_path = True | 678 | + install_path.mkdir(parents=True, exist_ok=True) |
| 679 | + except OSError as e: | ||
| 680 | + raise RuntimeError(f"failed to create static kernel install directory {install_path}: {e}") from e | ||
| 681 | + _current_install_path = install_path | ||
| 682 | + _owns_install_path = pid | ||
| 680 | return _current_install_path | 683 | return _current_install_path |
| 681 | 684 | ||
| 682 | 685 | ||
| @@ -701,7 +704,7 @@ def _install_run_packages(result_root: Path, rank: int = None): | |||
| 701 | filename = run_pkg.name | 704 | filename = run_pkg.name |
| 702 | try: | 705 | try: |
| 703 | if _use_process_isolation: | 706 | if _use_process_isolation: |
| 704 | - install_path = _get_or_create_install_path(result_root) | 707 | + install_path = _get_or_create_install_path() |
| 705 | install_cmd = [str(run_pkg), f"--install-path={install_path}"] | 708 | install_cmd = [str(run_pkg), f"--install-path={install_path}"] |
| 706 | else: | 709 | else: |
| 707 | install_cmd = [str(run_pkg)] | 710 | install_cmd = [str(run_pkg)] |
| @@ -853,7 +856,7 @@ def save_uninstall_info(filename: str): | |||
| 853 | def uninstall_static_kernel(): | 856 | def uninstall_static_kernel(): |
| 854 | if _use_process_isolation: | 857 | if _use_process_isolation: |
| 855 | global _owns_install_path, _current_install_path | 858 | global _owns_install_path, _current_install_path |
| 856 | - if _owns_install_path and _current_install_path is not None: | 859 | + if _owns_install_path == os.getpid() and _current_install_path is not None: |
| 857 | try: | 860 | try: |
| 858 | shutil.rmtree(_current_install_path) | 861 | shutil.rmtree(_current_install_path) |
| 859 | logger.debug(f"cleaned up install path: {_current_install_path}") | 862 | logger.debug(f"cleaned up install path: {_current_install_path}") |
| @@ -866,7 +869,7 @@ def uninstall_static_kernel(): | |||
| 866 | logger.debug(f"removed empty install dir: {_current_install_path.parent}") | 869 | logger.debug(f"removed empty install dir: {_current_install_path.parent}") |
| 867 | except OSError: | 870 | except OSError: |
| 868 | pass | 871 | pass |
| 869 | - _owns_install_path = False | 872 | + _owns_install_path = None |
| 870 | _current_install_path = None | 873 | _current_install_path = None |
| 871 | return | 874 | return |
| 872 | 875 | ||