diff options
Diffstat (limited to 'bitbake/lib/bb/__init__.py')
-rw-r--r-- | bitbake/lib/bb/__init__.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/bitbake/lib/bb/__init__.py b/bitbake/lib/bb/__init__.py index bf4c54d829..3c98b835c6 100644 --- a/bitbake/lib/bb/__init__.py +++ b/bitbake/lib/bb/__init__.py | |||
@@ -37,6 +37,34 @@ class BBHandledException(Exception): | |||
37 | import os | 37 | import os |
38 | import logging | 38 | import logging |
39 | from collections import namedtuple | 39 | from collections import namedtuple |
40 | import multiprocessing as mp | ||
41 | |||
42 | # Python 3.14 changes the default multiprocessing context from "fork" to | ||
43 | # "forkserver". However, bitbake heavily relies on "fork" behavior to | ||
44 | # efficiently pass data to the child processes. Places that need this should do: | ||
45 | # from bb import multiprocessing | ||
46 | # in place of | ||
47 | # import multiprocessing | ||
48 | |||
49 | class MultiprocessingContext(object): | ||
50 | """ | ||
51 | Multiprocessing proxy object that uses the "fork" context for a property if | ||
52 | available, otherwise goes to the main multiprocessing module. This allows | ||
53 | it to be a drop-in replacement for the multiprocessing module, but use the | ||
54 | fork context | ||
55 | """ | ||
56 | def __init__(self): | ||
57 | super().__setattr__("_ctx", mp.get_context("fork")) | ||
58 | |||
59 | def __getattr__(self, name): | ||
60 | if hasattr(self._ctx, name): | ||
61 | return getattr(self._ctx, name) | ||
62 | return getattr(mp, name) | ||
63 | |||
64 | def __setattr__(self, name, value): | ||
65 | raise AttributeError(f"Unable to set attribute {name}") | ||
66 | |||
67 | multiprocessing = MultiprocessingContext() | ||
40 | 68 | ||
41 | 69 | ||
42 | class NullHandler(logging.Handler): | 70 | class NullHandler(logging.Handler): |