2626import types
2727import warnings
2828from abc import ABCMeta , abstractmethod
29+ from collections .abc import Container
2930from pathlib import Path
3031from tempfile import TemporaryDirectory
3132from textwrap import dedent
@@ -471,7 +472,7 @@ class PythonVirtualenvOperator(_BasePythonVirtualenvOperator):
471472 :param expect_airflow: expect Airflow to be installed in the target environment. If true, the operator
472473 will raise warning if Airflow is not installed, and it will attempt to load Airflow
473474 macros when starting.
474- :param skip_exit_code : If python_callable exits with this exit code, leave the task
475+ :param skip_on_exit_code : If python_callable exits with this exit code, leave the task
475476 in ``skipped`` state (default: None). If set to ``None``, any non-zero
476477 exit code will be treated as a failure.
477478 """
@@ -494,7 +495,7 @@ def __init__(
494495 templates_dict : dict | None = None ,
495496 templates_exts : list [str ] | None = None ,
496497 expect_airflow : bool = True ,
497- skip_exit_code : int | None = None ,
498+ skip_on_exit_code : int | Container [ int ] | None = None ,
498499 ** kwargs ,
499500 ):
500501 if (
@@ -518,7 +519,13 @@ def __init__(
518519 self .python_version = python_version
519520 self .system_site_packages = system_site_packages
520521 self .pip_install_options = pip_install_options
521- self .skip_exit_code = skip_exit_code
522+ self .skip_on_exit_code = (
523+ skip_on_exit_code
524+ if isinstance (skip_on_exit_code , Container )
525+ else [skip_on_exit_code ]
526+ if skip_on_exit_code
527+ else []
528+ )
522529 super ().__init__ (
523530 python_callable = python_callable ,
524531 use_dill = use_dill ,
@@ -557,8 +564,8 @@ def execute_callable(self):
557564 try :
558565 result = self ._execute_python_callable_in_subprocess (python_path , tmp_path )
559566 except subprocess .CalledProcessError as e :
560- if self . skip_exit_code and e .returncode == self .skip_exit_code :
561- raise AirflowSkipException (f"Process exited with code { self . skip_exit_code } . Skipping." )
567+ if e .returncode in self .skip_on_exit_code :
568+ raise AirflowSkipException (f"Process exited with code { e . returncode } . Skipping." )
562569 else :
563570 raise
564571 return result
0 commit comments