From f82852fcde01a195bd5290987f1da947d80b6b7b Mon Sep 17 00:00:00 2001 From: Patricio Cubillos Date: Fri, 31 May 2024 08:34:25 +0200 Subject: [PATCH] Testing spawning for windows --- .github/workflows/python-package.yml | 4 ++-- mc3/chain.py | 7 ++++++- mc3/mcmc_driver.py | 10 ++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 2505b8f..6d39702 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -63,14 +63,14 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install cibuildwheel run: python -m pip install cibuildwheel==2.17.0 - - name: Build wheels + - name: Build wheels and run pytest run: python -m cibuildwheel --output-dir wheelhouse env: CIBW_BEFORE_BUILD: "pip install numpy" diff --git a/mc3/chain.py b/mc3/chain.py index 882d99e..47a0fd6 100644 --- a/mc3/chain.py +++ b/mc3/chain.py @@ -1,6 +1,7 @@ # Copyright (c) 2015-2023 Patricio Cubillos and contributors. # mc3 is open-source software under the MIT license (see LICENSE). +import platform import sys import warnings import random @@ -13,9 +14,13 @@ # Ingnore RuntimeWarnings: warnings.simplefilter("ignore", RuntimeWarning) +if platform.system() == 'Windows': + multiprocess_context = mp.get_context('spawn') +else: + multiprocess_context = mp.get_context('fork') -class Chain(mp.get_context('fork').Process): +class Chain(multiprocess_context.Process): """ Background process. This guy evaluates the model and calculates chisq. """ diff --git a/mc3/mcmc_driver.py b/mc3/mcmc_driver.py index e7e187a..b4c3c0c 100644 --- a/mc3/mcmc_driver.py +++ b/mc3/mcmc_driver.py @@ -5,6 +5,7 @@ 'mcmc', ] +import platform import time import ctypes import multiprocessing as mpr @@ -206,11 +207,16 @@ def mcmc( ncpp[0:nchains % ncpu] += 1 # Launch Chains: - mp_context = mpr.get_context('fork') + if platform.system() == 'Windows': + multiprocess_context = mp.get_context('spawn') + else: + multiprocess_context = mp.get_context('fork') + + #mp_context = mpr.get_context('fork') pipes = [] chains = [] for i in range(ncpu): - p = mp_context.Pipe() + p = multiprocess_context.Pipe() pipes.append(p[0]) chains.append( ch.Chain(func, indparams, indparams_dict, p[1], data, uncert,