1313# permissions and limitations under the License.
1414"""Pipeline execution utilities."""
1515
16+ import contextvars
1617from contextlib import contextmanager
1718from typing import (
1819 TYPE_CHECKING ,
2526
2627from zenml .client import Client
2728from zenml .config .step_configurations import StepConfigurationUpdate
28- from zenml .constants import (
29- ENV_ZENML_PREVENT_PIPELINE_EXECUTION ,
30- handle_bool_env_var ,
31- )
3229from zenml .exceptions import RunMonitoringError
3330from zenml .logger import get_logger
3431from zenml .models import (
3734)
3835from zenml .orchestrators .publish_utils import publish_failed_pipeline_run
3936from zenml .stack import Stack
40- from zenml .utils import (
41- env_utils ,
42- )
4337
4438if TYPE_CHECKING :
4539 StepConfigurationUpdateOrDict = Union [
4943logger = get_logger (__name__ )
5044
5145
46+ _prevent_pipeline_execution = contextvars .ContextVar (
47+ "prevent_pipeline_execution" , default = False
48+ )
49+
50+
5251def should_prevent_pipeline_execution () -> bool :
5352 """Whether to prevent pipeline execution.
5453
5554 Returns:
5655 Whether to prevent pipeline execution.
5756 """
58- return handle_bool_env_var (
59- ENV_ZENML_PREVENT_PIPELINE_EXECUTION , default = False
60- )
57+ return _prevent_pipeline_execution .get ()
6158
6259
6360@contextmanager
@@ -67,10 +64,11 @@ def prevent_pipeline_execution() -> Generator[None, None, None]:
6764 Yields:
6865 None.
6966 """
70- with env_utils .temporary_environment (
71- {ENV_ZENML_PREVENT_PIPELINE_EXECUTION : "True" }
72- ):
67+ token = _prevent_pipeline_execution .set (True )
68+ try :
7369 yield
70+ finally :
71+ _prevent_pipeline_execution .reset (token )
7472
7573
7674def submit_pipeline (
0 commit comments