diff --git a/src/lightning_lite/strategies/launchers/subprocess_script.py b/src/lightning_lite/strategies/launchers/subprocess_script.py index c28946faa9ab6..07af414e23bc3 100644 --- a/src/lightning_lite/strategies/launchers/subprocess_script.py +++ b/src/lightning_lite/strategies/launchers/subprocess_script.py @@ -17,7 +17,6 @@ from time import sleep from typing import Any, Callable, Sequence -import __main__ import numpy as np from lightning_utilities.core.imports import RequirementCache @@ -142,6 +141,8 @@ def _check_can_spawn_children(self) -> None: def _basic_subprocess_cmd() -> Sequence[str]: + import __main__ # local import to avoid https://github.com/Lightning-AI/lightning/issues/15218 + if __main__.__spec__ is None: # pragma: no-cover return [sys.executable, os.path.abspath(sys.argv[0])] + sys.argv[1:] else: @@ -149,6 +150,7 @@ def _basic_subprocess_cmd() -> Sequence[str]: def _hydra_subprocess_cmd(local_rank: int) -> Sequence[str]: + import __main__ # local import to avoid https://github.com/Lightning-AI/lightning/issues/15218 from hydra.core.hydra_config import HydraConfig from hydra.utils import to_absolute_path diff --git a/src/pytorch_lightning/CHANGELOG.md b/src/pytorch_lightning/CHANGELOG.md index dc4292fdfc98a..159cb97097120 100644 --- a/src/pytorch_lightning/CHANGELOG.md +++ b/src/pytorch_lightning/CHANGELOG.md @@ -186,6 +186,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed batch normalization statistics calculation in `StochasticWeightAveraging` callback ([#14866](https://github.com/Lightning-AI/lightning/pull/14866)) - Avoided initializing optimizers during deepspeed inference ([#14944](https://github.com/Lightning-AI/lightning/pull/14944)) - Fixed `LightningCLI` parse_env and description in subcommands ([#15138](https://github.com/Lightning-AI/lightning/pull/15138)) +- Fixed an exception that would occur when creating a `multiprocessing.Pool` after importing Lightning ([#15292](https://github.com/Lightning-AI/lightning/pull/15292)) ## [1.7.7] - 2022-09-22