Skip to content

Commit f1ed44a

Browse files
committed
Use context var to prevent pipeline execution
1 parent fe0804a commit f1ed44a

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/zenml/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ def handle_int_env_var(var: str, default: int = 0) -> int:
140140
ENV_ZENML_LOGGING_VERBOSITY = "ZENML_LOGGING_VERBOSITY"
141141
ENV_ZENML_LOGGING_FORMAT = "ZENML_LOGGING_FORMAT"
142142
ENV_ZENML_REPOSITORY_PATH = "ZENML_REPOSITORY_PATH"
143-
ENV_ZENML_PREVENT_PIPELINE_EXECUTION = "ZENML_PREVENT_PIPELINE_EXECUTION"
144143
ENV_ZENML_ENABLE_RICH_TRACEBACK = "ZENML_ENABLE_RICH_TRACEBACK"
145144
ENV_ZENML_ACTIVE_STACK_ID = "ZENML_ACTIVE_STACK_ID"
146145
ENV_ZENML_ACTIVE_PROJECT_ID = "ZENML_ACTIVE_PROJECT_ID"

src/zenml/execution/pipeline/utils.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# permissions and limitations under the License.
1414
"""Pipeline execution utilities."""
1515

16+
import contextvars
1617
from contextlib import contextmanager
1718
from typing import (
1819
TYPE_CHECKING,
@@ -25,10 +26,6 @@
2526

2627
from zenml.client import Client
2728
from zenml.config.step_configurations import StepConfigurationUpdate
28-
from zenml.constants import (
29-
ENV_ZENML_PREVENT_PIPELINE_EXECUTION,
30-
handle_bool_env_var,
31-
)
3229
from zenml.exceptions import RunMonitoringError
3330
from zenml.logger import get_logger
3431
from zenml.models import (
@@ -37,9 +34,6 @@
3734
)
3835
from zenml.orchestrators.publish_utils import publish_failed_pipeline_run
3936
from zenml.stack import Stack
40-
from zenml.utils import (
41-
env_utils,
42-
)
4337

4438
if TYPE_CHECKING:
4539
StepConfigurationUpdateOrDict = Union[
@@ -49,15 +43,18 @@
4943
logger = get_logger(__name__)
5044

5145

46+
_prevent_pipeline_execution = contextvars.ContextVar(
47+
"prevent_pipeline_execution", default=False
48+
)
49+
50+
5251
def 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

7674
def submit_pipeline(

0 commit comments

Comments
 (0)