posit-dev / posit-dev/positron
Python multiprocessing only works in "fork"
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.3k
- Forks
- 184
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 206
Description
System details:
Positron and OS details:
Positron Version: 2025.04.0 (Universal) build 64
Code - OSS Version: 1.96.0
Commit: b25e18713d464fb01352d31f7a165f1fb79d42c4
Date: 2025-03-10T02:32:22.057Z (5 days ago)
Electron: 32.2.6
Chromium: 128.0.6613.186
Node.js: 20.18.1
V8: 12.8.374.38-electron.0
OS: Darwin arm64 24.1.0
Interpreter details:
Python 3.13.2 | packaged by conda-forge | (main, Feb 17 2025, 14:02:48) [Clang 18.1.8 ]
Describe the issue:
When trying to run python code using the multiprocessing library, I get errors when it uses the default "spawn" start mode, and only runs properly in "fork"
Steps to reproduce the issue:
Example 1:
import multiprocessing as mp
def foo(q):
q.put('hello')
if __name__ == '__main__':
mp.set_start_method('spawn')
q = mp.Queue()
p = mp.Process(target=foo, args=(q,))
p.start()
print(q.get())
p.join()
Example 2:
import multiprocessing as mp
def foo(q):
q.put('hello')
if __name__ == '__main__':
mp.set_start_method('fork')
q = mp.Queue()
p = mp.Process(target=foo, args=(q,))
p.start()
print(q.get())
p.join()
Expected or desired behavior:
If I am understanding the documentation correctly, the default is "spawn" as thats safer. Would have to update all the code to use "fork" to operate properly in positron. Works fine in Rstudio.
https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing
Were there any error messages in the UI, Output panel, or Developer Tools console?
Traceback (most recent call last):
File "<string>", line 1, in <module>
from multiprocessing.spawn import spawn_main; spawn_main(tracker_fd=87, pipe_handle=91)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/nate/anaconda3/envs/py313/lib/python3.13/multiprocessing/spawn.py", line 122, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "/Users/nate/anaconda3/envs/py313/lib/python3.13/multiprocessing/spawn.py", line 132, in _main
self = reduction.pickle.load(from_parent)
AttributeError: Can't get attribute 'foo' on <module '__main__' (<class '_frozen_importlib.BuiltinImporter'>)>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two multiprocessing examples from the issue in Positron with Python 3.13, then inspect the reported spawn traceback and how Python code is launched. Done means the spawn example runs successfully and prints "hello" without requiring the fork start method.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100