diff --git a/pyproject.toml b/pyproject.toml index 68b5209c..0afb3b91 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,6 +84,8 @@ filterwarnings = """ error ignore:numpy.ufunc size changed ignore:The explicit passing of coroutine objects to asyncio.wait() + ignore::DeprecationWarning:multiprocessing.reduction + """ # Doctest python code in docs, python code in src docstrings, test functions in tests testpaths = "docs src tests" diff --git a/tests/fixtures/mocked_panda.py b/tests/fixtures/mocked_panda.py index f00d292c..e7165d76 100644 --- a/tests/fixtures/mocked_panda.py +++ b/tests/fixtures/mocked_panda.py @@ -7,7 +7,7 @@ from io import BufferedReader from itertools import chain, repeat from logging import handlers -from multiprocessing import Queue, get_context +from multiprocessing import Queue, get_context, set_start_method from multiprocessing.connection import Connection from pathlib import Path from typing import Any, Optional, TypeVar @@ -250,7 +250,12 @@ def get_multiprocessing_context(): start_method = "spawn" else: start_method = "forkserver" - return get_context(start_method) + + set_start_method(start_method, force=True) + return get_context() + + +MULTIPROCESSING_CONTEXT = get_multiprocessing_context() def enable_codecov_multiprocess(): @@ -318,8 +323,7 @@ def caplog_workaround(): @contextmanager def ctx() -> Generator[None, None, None]: - ctx = get_multiprocessing_context() - logger_queue = ctx.Queue() + logger_queue = MULTIPROCESSING_CONTEXT.Queue() logger = logging.getLogger() logger.addHandler(handlers.QueueHandler(logger_queue)) yield diff --git a/tests/test_hdf_ioc.py b/tests/test_hdf_ioc.py index a2f4eaec..f50be2d6 100644 --- a/tests/test_hdf_ioc.py +++ b/tests/test_hdf_ioc.py @@ -27,13 +27,13 @@ from softioc import asyncio_dispatcher, builder, softioc from fixtures.mocked_panda import ( + MULTIPROCESSING_CONTEXT, TIMEOUT, MockedAsyncioClient, Rows, append_random_uppercase, custom_logger, enable_codecov_multiprocess, - get_multiprocessing_context, select_and_recv, ) from pandablocks_ioc._hdf_ioc import ( @@ -278,9 +278,8 @@ def hdf5_subprocess_ioc_no_logging_check( test_prefix, hdf5_test_prefix = new_random_hdf5_prefix - ctx = get_multiprocessing_context() - parent_conn, child_conn = ctx.Pipe() - p = ctx.Process( + parent_conn, child_conn = MULTIPROCESSING_CONTEXT.Pipe() + p = MULTIPROCESSING_CONTEXT.Process( target=subprocess_func, args=(test_prefix, standard_responses, child_conn) ) try: @@ -307,9 +306,8 @@ def hdf5_subprocess_ioc( with caplog.at_level(logging.WARNING): with caplog_workaround(): - ctx = get_multiprocessing_context() - parent_conn, child_conn = ctx.Pipe() - p = ctx.Process( + parent_conn, child_conn = MULTIPROCESSING_CONTEXT.Pipe() + p = MULTIPROCESSING_CONTEXT.Process( target=subprocess_func, args=(test_prefix, standard_responses, child_conn), )