summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bitbake/lib/bb/__init__.py28
-rw-r--r--bitbake/lib/bb/asyncrpc/serv.py2
-rw-r--r--bitbake/lib/bb/cooker.py2
-rw-r--r--bitbake/lib/bb/server/process.py2
-rw-r--r--bitbake/lib/bb/tests/support/httpserver.py4
-rw-r--r--bitbake/lib/bb/utils.py4
-rw-r--r--bitbake/lib/hashserv/tests.py2
7 files changed, 35 insertions, 9 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):
37import os 37import os
38import logging 38import logging
39from collections import namedtuple 39from collections import namedtuple
40import 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
49class 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
67multiprocessing = MultiprocessingContext()
40 68
41 69
42class NullHandler(logging.Handler): 70class NullHandler(logging.Handler):
diff --git a/bitbake/lib/bb/asyncrpc/serv.py b/bitbake/lib/bb/asyncrpc/serv.py
index a66117acad..953c02ef3e 100644
--- a/bitbake/lib/bb/asyncrpc/serv.py
+++ b/bitbake/lib/bb/asyncrpc/serv.py
@@ -11,7 +11,7 @@ import os
11import signal 11import signal
12import socket 12import socket
13import sys 13import sys
14import multiprocessing 14from bb import multiprocessing
15import logging 15import logging
16from .connection import StreamConnection, WebsocketConnection 16from .connection import StreamConnection, WebsocketConnection
17from .exceptions import ClientError, ServerError, ConnectionClosedError, InvokeError 17from .exceptions import ClientError, ServerError, ConnectionClosedError, InvokeError
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 6fce19b464..778cbb5897 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -12,7 +12,7 @@
12import sys, os, glob, os.path, re, time 12import sys, os, glob, os.path, re, time
13import itertools 13import itertools
14import logging 14import logging
15import multiprocessing 15from bb import multiprocessing
16import threading 16import threading
17from io import StringIO, UnsupportedOperation 17from io import StringIO, UnsupportedOperation
18from contextlib import closing 18from contextlib import closing
diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py
index 76b189291d..34b3a2ae9d 100644
--- a/bitbake/lib/bb/server/process.py
+++ b/bitbake/lib/bb/server/process.py
@@ -13,7 +13,7 @@
13import bb 13import bb
14import bb.event 14import bb.event
15import logging 15import logging
16import multiprocessing 16from bb import multiprocessing
17import threading 17import threading
18import array 18import array
19import os 19import os
diff --git a/bitbake/lib/bb/tests/support/httpserver.py b/bitbake/lib/bb/tests/support/httpserver.py
index 78f7660053..03327e923b 100644
--- a/bitbake/lib/bb/tests/support/httpserver.py
+++ b/bitbake/lib/bb/tests/support/httpserver.py
@@ -3,7 +3,7 @@
3# 3#
4 4
5import http.server 5import http.server
6import multiprocessing 6from bb import multiprocessing
7import os 7import os
8import traceback 8import traceback
9import signal 9import signal
@@ -43,7 +43,7 @@ class HTTPService(object):
43 self.process = multiprocessing.Process(target=self.server.server_start, args=[self.root_dir, self.logger]) 43 self.process = multiprocessing.Process(target=self.server.server_start, args=[self.root_dir, self.logger])
44 44
45 # The signal handler from testimage.bbclass can cause deadlocks here 45 # The signal handler from testimage.bbclass can cause deadlocks here
46 # if the HTTPServer is terminated before it can restore the standard 46 # if the HTTPServer is terminated before it can restore the standard
47 #signal behaviour 47 #signal behaviour
48 orig = signal.getsignal(signal.SIGTERM) 48 orig = signal.getsignal(signal.SIGTERM)
49 signal.signal(signal.SIGTERM, signal.SIG_DFL) 49 signal.signal(signal.SIGTERM, signal.SIG_DFL)
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index d2f11e4377..1b4fb93a30 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -14,7 +14,7 @@ import logging
14import bb 14import bb
15import bb.msg 15import bb.msg
16import locale 16import locale
17import multiprocessing 17from bb import multiprocessing
18import fcntl 18import fcntl
19import importlib 19import importlib
20import importlib.machinery 20import importlib.machinery
@@ -1174,8 +1174,6 @@ def process_profilelog(fn, pout = None):
1174# 1174#
1175def multiprocessingpool(*args, **kwargs): 1175def multiprocessingpool(*args, **kwargs):
1176 1176
1177 import multiprocessing.pool
1178 #import multiprocessing.util
1179 #multiprocessing.util.log_to_stderr(10) 1177 #multiprocessing.util.log_to_stderr(10)
1180 # Deal with a multiprocessing bug where signals to the processes would be delayed until the work 1178 # Deal with a multiprocessing bug where signals to the processes would be delayed until the work
1181 # completes. Putting in a timeout means the signals (like SIGINT/SIGTERM) get processed. 1179 # completes. Putting in a timeout means the signals (like SIGINT/SIGTERM) get processed.
diff --git a/bitbake/lib/hashserv/tests.py b/bitbake/lib/hashserv/tests.py
index 5349cd5867..ed1ade749c 100644
--- a/bitbake/lib/hashserv/tests.py
+++ b/bitbake/lib/hashserv/tests.py
@@ -11,7 +11,7 @@ from bb.asyncrpc import InvokeError
11from .client import ClientPool 11from .client import ClientPool
12import hashlib 12import hashlib
13import logging 13import logging
14import multiprocessing 14from bb import multiprocessing
15import os 15import os
16import sys 16import sys
17import tempfile 17import tempfile