gwastro / pycbc

Core package to analyze gravitational-wave data, find signals, and study their parameters. This package was used in the first direct detection of gravitational waves (GW150914), and is used in the ongoing analysis of LIGO/Virgo data.
http://pycbc.org
GNU General Public License v3.0
313 stars 347 forks source link

[conflict] Multiprocessing start method on macOS #4853

Open xkzl opened 3 weeks ago

xkzl commented 3 weeks ago

Hello,

I have many conflicts with other imports on macOS using PyCBC due to: https://github.com/gwastro/pycbc/blob/master/pycbc/__init__.py#L211C1-L216C49

 # MacosX after python3.7 switched to 'spawn', however, this does not
    # preserve common state information which we have relied on when using
    # multiprocessing based pools.
    import multiprocessing
    if hasattr(multiprocessing, 'set_start_method'):
        multiprocessing.set_start_method('fork')

Here is a typical error message:

  File "/Users/marcomeyer/.conda/envs/myenv/lib/python3.11/multiprocessing/context.py", line 248, in set_start_method
    raise RuntimeError('context has already been set')
RuntimeError: context has already been set

I assume this is used for performances, but in my case I don't use pycbc for heavy computation. Is there any chance to use spawn method or just disable this method using a custom variable maybe ?

ahnitz commented 3 weeks ago

@xkzl Does this PR https://github.com/gwastro/pycbc/pull/4620 address the issue in your use case? If not, we are happy to accept PRs here to help improve this behavior for everyone. Or suggestions for how you'd like this to work.