File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77
88[project ]
99name = " spotpython"
10- version = " 0.29.15 "
10+ version = " 0.29.16 "
1111authors = [
1212 { name =" T. Bartz-Beielstein" , email =" tbb@bartzundbartz.de" }
1313]
Original file line number Diff line number Diff line change 88import json
99from numpy .random import default_rng
1010from spotpython .design .spacefilling import SpaceFilling
11- from multiprocessing import set_start_method
11+ from multiprocessing import set_start_method , get_start_method
1212
1313# old Kriging with attribute "name" kriging
1414from spotpython .build .kriging import Kriging as OldKriging
5656# matplotlib.use("TkAgg")
5757# matplotlib.use("Agg")
5858
59- # for multiprocessing:
60- set_start_method ("spawn" )
61-
6259logger = logging .getLogger (__name__ )
6360# configure the handler and formatter as needed
6461py_handler = logging .FileHandler (f"{ __name__ } .log" , mode = "w" )
@@ -205,6 +202,13 @@ def __init__(
205202 self .optimizer_control = optimizer_control
206203 self .surrogate_control = surrogate_control
207204
205+ # for multiprocessing:
206+ # check if context is already set to "spawn"
207+ # if not, set it to "spawn"
208+ # Check if the context is already set to "spawn"
209+ if get_start_method (allow_none = True ) != "spawn" :
210+ set_start_method ("spawn" , force = True )
211+
208212 # small value:
209213 self .eps = sqrt (spacing (1 ))
210214
Original file line number Diff line number Diff line change 1+ from multiprocessing import get_start_method , set_start_method
2+
3+ def test_multiprocessing_context_spawn ():
4+ """
5+ Test that the multiprocessing context is set to 'spawn' if it is not already set.
6+ """
7+ # Check the current start method
8+ current_method = get_start_method (allow_none = True )
9+
10+ # If the current method is not 'spawn', set it to 'spawn'
11+ if current_method != "spawn" :
12+ set_start_method ("spawn" , force = True )
13+
14+ # Verify that the start method is now 'spawn'
15+ assert get_start_method () == "spawn" , "The multiprocessing context should be set to 'spawn'."
You can’t perform that action at this time.
0 commit comments