diff --git a/metaflow/plugins/cards/card_cli.py b/metaflow/plugins/cards/card_cli.py index 9cb8b4bbb9d..70ca05d0a67 100644 --- a/metaflow/plugins/cards/card_cli.py +++ b/metaflow/plugins/cards/card_cli.py @@ -15,6 +15,7 @@ import json import uuid import signal +import sys import random from contextlib import contextmanager from functools import wraps @@ -161,8 +162,11 @@ def resolve_card( @contextmanager def timeout(time): # Register a function to raise a TimeoutError on the signal. + if sys.platform == "win32": + raise RuntimeError( + "Card timeout is not supported on Windows (SIGALRM is POSIX-only)." + ) signal.signal(signal.SIGALRM, raise_timeout) - # Schedule the signal to be sent after ``time``. signal.alarm(time) try: diff --git a/metaflow/plugins/timeout_decorator.py b/metaflow/plugins/timeout_decorator.py index 91c1814ff33..0855db9830a 100644 --- a/metaflow/plugins/timeout_decorator.py +++ b/metaflow/plugins/timeout_decorator.py @@ -1,4 +1,5 @@ import signal +import sys import traceback from metaflow.exception import MetaflowException @@ -70,6 +71,12 @@ def task_pre_step( if ubf_context != UBF_CONTROL and retry_count <= max_user_code_retries: # enable timeout only when executing user code self.step_name = step_name + if sys.platform == "win32": + raise MetaflowException( + "@timeout is not supported on Windows because it relies on " + "POSIX signals (SIGALRM). Use a Linux-based compute backend " + "(e.g. @kubernetes or @batch) to use @timeout." + ) signal.signal(signal.SIGALRM, self._sigalrm_handler) signal.alarm(self.secs)