Skip to content

Sample code with multiprocessing freeze_support and set_start_method fails #140814

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.

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.13only security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixesdocsDocumentation in the Doc dirtopic-multiprocessing

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions