Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/build/lib/airflow/utils/mixins.py: 50%
24 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
1#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
19from __future__ import annotations
21import multiprocessing
22import typing
24from airflow.configuration import conf
25from airflow.utils.context import Context
27if typing.TYPE_CHECKING:
28 import multiprocessing.context
30 from airflow.models.operator import Operator
33class MultiprocessingStartMethodMixin:
34 """Convenience class to add support for different types of multiprocessing."""
36 def _get_multiprocessing_start_method(self) -> str:
37 """
38 Determine method of creating new processes by checking if the
39 mp_start_method is set in configs, else, it uses the OS default.
40 """
41 if conf.has_option("core", "mp_start_method"):
42 return conf.get_mandatory_value("core", "mp_start_method")
44 method = multiprocessing.get_start_method()
45 if not method:
46 raise ValueError("Failed to determine start method")
47 return method
49 def _get_multiprocessing_context(self) -> multiprocessing.context.DefaultContext:
50 mp_start_method = self._get_multiprocessing_start_method()
51 return multiprocessing.get_context(mp_start_method) # type: ignore
54class ResolveMixin:
55 """A runtime-resolved value."""
57 def iter_references(self) -> typing.Iterable[tuple[Operator, str]]:
58 """Find underlying XCom references this contains.
60 This is used by the DAG parser to recursively find task dependencies.
62 :meta private:
63 """
64 raise NotImplementedError
66 def resolve(self, context: Context) -> typing.Any:
67 """Resolve this value for runtime.
69 :meta private:
70 """
71 raise NotImplementedError