diff options
author | Joshua Watt <JPEWhacker@gmail.com> | 2025-08-22 00:40:06 +0200 |
---|---|---|
committer | Steve Sakoman <steve@sakoman.com> | 2025-09-17 15:36:44 -0700 |
commit | f00c4968ff34c6a23f2467f310b5aae31ab4947c (patch) | |
tree | e48efe2f0c4b596ce75e3b52d37b7cd341130c51 /bitbake/lib/bb/__init__.py | |
parent | 6400741e0c11d1620a5ebe394d24deec295236f9 (diff) | |
download | poky-f00c4968ff34c6a23f2467f310b5aae31ab4947c.tar.gz |
bitbake: Use a "fork" multiprocessing context
Python 3.14 changes the default multiprocessing context from "fork" to
"forkserver"; however bitbake heavily relies on "fork" to efficiently
pass data to the child processes. As such, make "fork" context in the bb
namespace and use it in place of the normal multiprocessing module.
Note that multiprocessing contexts were added in Python 3.4, so this
should be safe to use even before Python 3.14
[YOCTO #15858]
(Bitbake rev: 15d7448e04aa78c827d2cef9eb1a62bd6e0dd119)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Martin Jansa <martin.jansa@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
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 cdec9e4d6c..f59c2515b7 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): |