Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: PyBaMM fails to import when user has already imported a library that uses mp.set_start_method #3997

Closed
aabills opened this issue Apr 11, 2024 · 1 comment · Fixed by #4001
Assignees
Labels
bug Something isn't working

Comments

@aabills
Copy link
Contributor

aabills commented Apr 11, 2024

PyBaMM Version

develop

Python Version

3.11

Describe the bug

PyBaMM fails to import when importing a library that uses multiprocessing and has already set the start method to something other than fork, as a result of #3975. This should be apparent when reading the documentation for mp.set_start_method

Pending a long-term solution, I think that #3975 should at least have mp.set_start_method wrapped in a try-except -- most people, most of the time, do not really need the multiprocessing functionality, and I don't think pybamm should force those users to modify their multiprocessing configuration. It can throw a warning saying multiprocessing is not available or whatever.

Other solutions are welcome, of course.

Steps to Reproduce

module thing:

import multiprocessing as mp

mp.set_start_method("spawn")

def hello():
    print("hello, world")

script:

import thing
import pybamm

Relevant log output

❯ python main.py 
Traceback (most recent call last):
  File "/Users/abills/.../main.py", line 2, in <module>
    import pybamm
  File "/Users/abills/.../python3.11/site-packages/pybamm/__init__.py", line 204, in <module>
    from .solvers.base_solver import BaseSolver
  File "/Users/abills/.../python3.11/site-packages/pybamm/solvers/base_solver.py", line 18, in <module>
    mp.set_start_method("fork")
  File "/Users/abills/.../python3.11/multiprocessing/context.py", line 247, in set_start_method
    raise RuntimeError('context has already been set')
RuntimeError: context has already been set
@aabills aabills added the bug Something isn't working label Apr 11, 2024
@aabills aabills changed the title [Bug]: PyBaMM fails to import when importing a library that uses mp.set_start_method [Bug]: PyBaMM fails to import when user has already imported a library that uses mp.set_start_method Apr 11, 2024
@kratman
Copy link
Contributor

kratman commented Apr 11, 2024

@BradyPlanden Tagging you since the bug most likely comes from #3975

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants