Bug 15858 - _pickle.PicklingError with python-3.14
Summary: _pickle.PicklingError with python-3.14
Status: RESOLVED FIXED
Alias: None
Product: BitBake
Classification: Build System, Metadata & Runtime
Component: bitbake (show other bugs)
Version: unspecified
Hardware: x86 Multiple
: Medium+ normal
Target Milestone: 5.3 M3
Assignee: Joshua Watt
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2025-05-12 10:08 UTC by Martin Jansa
Modified: 2025-08-12 13:55 UTC (History)
6 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments
log.do_populate_sysroot.333633 with the exception (5.96 KB, text/plain)
2025-08-12 09:25 UTC, Martin Jansa
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Jansa 2025-05-12 10:08:24 UTC
With python-3.14 in gentoo bitbake fails to start with PicklingError

ERROR: Attempting to set server environment: Unable to update the server configuration with local parameters: Traceback (most recent call last):
  File "/OE/build/luneos-whinlatter/bitbake/lib/bb/command.py", line 91, in runCommand
    result = command_method(self, commandline)
  File "/OE/build/luneos-whinlatter/bitbake/lib/bb/command.py", line 291, in updateConfig
    command.cooker.updateConfigOpts(options, environment, cmdline)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/OE/build/luneos-whinlatter/bitbake/lib/bb/cooker.py", line 471, in updateConfigOpts
    self.reset()
    ~~~~~~~~~~^^
  File "/OE/build/luneos-whinlatter/bitbake/lib/bb/cooker.py", line 1741, in reset
    self.handlePRServ()
    ~~~~~~~~~~~~~~~~~^^
  File "/OE/build/luneos-whinlatter/bitbake/lib/bb/cooker.py", line 306, in handlePRServ
    self.prhost = prserv.serv.auto_start(self.data)
                  ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/OE/build/luneos-whinlatter/bitbake/lib/prserv/serv.py", line 444, in auto_start
    singleton.start()
    ~~~~~~~~~~~~~~~^^
  File "/OE/build/luneos-whinlatter/bitbake/lib/prserv/serv.py", line 246, in start
    self.process = self.prserv.serve_as_process(log_level=logging.WARNING)
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/OE/build/luneos-whinlatter/bitbake/lib/bb/asyncrpc/serv.py", line 402, in serve_as_process
    self.process.start()
    ~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.14/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
                  ~~~~~~~~~~~^^^^^^
  File "/usr/lib/python3.14/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/usr/lib/python3.14/multiprocessing/context.py", line 300, in _Popen
    return Popen(process_obj)
  File "/usr/lib/python3.14/multiprocessing/popen_forkserver.py", line 35, in __init__
    super().__init__(process_obj)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/usr/lib/python3.14/multiprocessing/popen_fork.py", line 20, in __init__
    self._launch(process_obj)
    ~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/usr/lib/python3.14/multiprocessing/popen_forkserver.py", line 47, in _launch
    reduction.dump(process_obj, buf)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
_pickle.PicklingError: Can't pickle local object <function AsyncServer.serve_as_process.<locals>.run at 0x7fa4972eaf00>
when serializing dict item '_target'
when serializing multiprocessing.context.Process state
when serializing multiprocessing.context.Process object
Comment 1 Joshua Watt 2025-07-03 19:12:42 UTC
This is likely caused by Python 3.14 changing the default way that multiprocess starts child processes away from the 'fork' method (see https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods). Bitbake relies heavily on the 'fork' method to share non-pickleable data with the child processes, so we'll need to change this for Python 3.14 compatability
Comment 2 Joshua Watt 2025-07-03 19:14:02 UTC
And by "change" I mean that we'll need to instruct the python multiprocess to continue using the 'fork' method using either get_context() or set_start_method() so that our code remains compatible
Comment 3 Jacob Panov 2025-07-21 18:56:20 UTC
Joshua is right with the straightforward fix - just force 'fork' method on 3.14+. I've got a patch ready that handles this with proper fallback for platforms that don't support fork.

Tested it by reproducing the original error (forcing spawn method) then confirming the fix prevents the PicklingError.

This is my first contribution so I figured I'd start small. Appreciate it!
Comment 4 Joshua Watt 2025-07-21 19:02:54 UTC
I also have a patch I've been testing for this
Comment 5 Jacob Panov 2025-07-21 19:07:24 UTC
Well what should we do then?

I have no idea how to navigate things like this.
Comment 6 Joshua Watt 2025-07-21 19:10:09 UTC
Feel free to send yours to the mailing list; We can look both over and see which we like better.

Thanks
Comment 7 Joshua Watt 2025-07-24 14:36:42 UTC
Fixed in bitbake 62be9113d98fccb347c6aa0a10d5c4ee2857f8b6
Comment 8 Martin Jansa 2025-08-12 09:25:52 UTC
Created attachment 5131 [details]
log.do_populate_sysroot.333633 with the exception
Comment 9 Martin Jansa 2025-08-12 09:26:28 UTC
Even with the mentioned patch applied I'm seeing PicklingErrors as shown in attachment (to preserve formatting).
Comment 10 Martin Jansa 2025-08-12 09:40:18 UTC
Do we need to update
meta/lib/oe/utils.py:import multiprocessing
as well? now with new bitbake version required by oe-core we might be able to use it.

It works for me, sent to ML:
https://lists.openembedded.org/g/openembedded-core/message/221758
Comment 11 Joshua Watt 2025-08-12 13:55:23 UTC
Yep, I forgot to loop back around and check OE after the bitbake fix. Thanks.