Skip to content

Commit

Permalink
ignored internal deprecation warning in multiprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Oct 30, 2024
1 parent 64e1054 commit 7013f5f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 8 additions & 4 deletions tests/fixtures/mocked_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions tests/test_hdf_ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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:
Expand All @@ -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),
)
Expand Down

0 comments on commit 7013f5f

Please sign in to comment.