question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiprocessing Tutorial Example Not Working

See original GitHub issue

General 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:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
dfmcommented, Nov 10, 2020

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

import multiprocessing as mp
mp.set_start_method('fork')

before executing the above code to see if that works.

1reaction
jorgenorenacommented, May 20, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found