Multiprocessing Tutorial Example Not Working
See original GitHub issueGeneral information:
- emcee version: 3.0.2
- platform: python, jupyter notebook
- installation method (pip/conda/source/other?): pip
Problem description:
Expected behavior: That the multiprocessing example using “pool” would work in a jupyter notebook for the example shown in the multiprocessing example.
Actual behavior: Using “pool” in the sampler does not converge and continues to run indefinitely. However, the example in the tutorial shows that it should finish running and run faster than the serial code.
What have you tried so far?: Modified the code, tried different notebooks, tried to use pool.close()
Minimal example:
from multiprocessing import Pool
with Pool() as pool:
    sampler = emcee.EnsembleSampler(nwalkers, ndim, log_prob, pool=pool)
    start = time.time()
    sampler.run_mcmc(initial, nsteps, progress=True)
    end = time.time()
    multi_time = end - start
    print("Multiprocessing took {0:.1f} seconds".format(multi_time))
    print("{0:.1f} times faster than serial".format(serial_time / multi_time))
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
 Top Results From Across the Web
Top Results From Across the Web
Multiprocess Python: Working code of a tutorial doesn't work ...
An attempt has been made to start a new process before the current process has finished its bootstrapping phase. This probably means that...
Read more >3 Multiprocessing Common Errors - Super Fast Python
In this tutorial, you will discover the common errors when creating child processes in ... Error 2: print() Does Not Work In Child...
Read more >Python Multiprocessing Example - DigitalOcean
In our previous tutorial, we learned about Python CSV Example. ... from multiprocessing import Pool import time work = (["A", 5], ["B", 2], ......
Read more >Python Multiprocessing Tutorial | TutorialEdge.net
In this example, I'll be showing you how to spawn multiple processes at once and each process will output the random number that...
Read more >multiprocessing — Process-based parallelism — Python 3.11 ...
This module does not work or is not available on WebAssembly platforms wasm32-emscripten and ... This basic example of data parallelism using Pool...
Read more > Top Related Medium Post
Top Related Medium Post
No results found
 Top Related StackOverflow Question
Top Related StackOverflow Question
No results found
 Troubleshoot Live Code
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free Top Related Reddit Thread
Top Related Reddit Thread
No results found
 Top Related Hackernoon Post
Top Related Hackernoon Post
No results found
 Top Related Tweet
Top Related Tweet
No results found
 Top Related Dev.to Post
Top Related Dev.to Post
No results found
 Top Related Hashnode Post
Top Related Hashnode Post
No results found

Thanks - are you on a mac? What version of Python?
The default settings for how multiprocessing on macOS have changed in Python 3.8 so that could be the cause. You could try running
before executing the above code to see if that works.
Hi, I was having a similar problem and this seems to have fixed the issue. I had to use the following line
mp.set_start_method('fork', force=True)Have you considered updating the documentation?