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()
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
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.
Documentation
On Python3.14 page https://docs.python.org/3/library/multiprocessing.html#multiprocessing-programming-forkserver there's an example:
My code has:
But on Ubuntu 25.10 that causes:
It seems that set_start_method() has to be called BEFORE freeze_support, not AFTER.
Linked PRs