Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/airflow/utils/mixins.py: 55%
20 statements
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +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 from airflow.models.operator import Operator
31class MultiprocessingStartMethodMixin:
32 """Convenience class to add support for different types of multiprocessing."""
34 def _get_multiprocessing_start_method(self) -> str:
35 """
36 Determine method of creating new processes by checking if the
37 mp_start_method is set in configs, else, it uses the OS default.
38 """
39 if conf.has_option("core", "mp_start_method"):
40 return conf.get_mandatory_value("core", "mp_start_method")
42 method = multiprocessing.get_start_method()
43 if not method:
44 raise ValueError("Failed to determine start method")
45 return method
48class ResolveMixin:
49 """A runtime-resolved value."""
51 def iter_references(self) -> typing.Iterable[tuple[Operator, str]]:
52 """Find underlying XCom references this contains.
54 This is used by the DAG parser to recursively find task dependencies.
56 :meta private:
57 """
58 raise NotImplementedError
60 def resolve(self, context: Context) -> typing.Any:
61 """Resolve this value for runtime.
63 :meta private:
64 """
65 raise NotImplementedError