Skip to content

Sample code with multiprocessing freeze_support and set_start_method fails #140814

@RobH123

Description

@RobH123

Documentation

On Python3.14 page https://docs.python.org/3/library/multiprocessing.html#multiprocessing-programming-forkserver there's an example:

from multiprocessing import Process, freeze_support, set_start_method

def foo():
    print('hello')

if __name__ == '__main__':
    freeze_support()
    set_start_method('spawn')
    p = Process(target=foo)
    p.start()

My code has:

if __name__ == '__main__':
    multiprocessing.freeze_support() # Multiprocessing support for frozen Windows executables
    multiprocessing.set_start_method('fork') # The default was changed on POSIX systems from 'fork' to 'forkserver' in Python3.14

But on Ubuntu 25.10 that causes:

Traceback (most recent call last):
  File "test.py", line 10705, in <module>
    multiprocessing.set_start_method('fork') # The default was changed on POSIX systems from 'fork' to 'forkserver' in Python3.14
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/usr/lib/python3.14/multiprocessing/context.py", line 247, in set_start_method
    raise RuntimeError('context has already been set')
RuntimeError: context has already been set

It seems that set_start_method() has to be called BEFORE freeze_support, not AFTER.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesdocsDocumentation in the Doc dirtopic-multiprocessing

    Projects

    Status

    No status

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions