Skip to content

Commit d70be38

Browse files
Copilotletmaik
andcommitted
Address code review feedback: fix stacklevel, improve URL anchor, clean up test
Co-authored-by: letmaik <530988+letmaik@users.noreply.github.com>
1 parent a3a411b commit d70be38

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

rawpy/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def _check_multiprocessing_fork():
4747
"This can cause deadlocks when OpenMP is enabled (which it is in this build). "
4848
"Please use mp.set_start_method('spawn') or mp.set_start_method('forkserver') "
4949
"at the start of your main module. "
50-
"See https://github.com/letmaik/rawpy#faq for more information.",
50+
"See https://github.com/letmaik/rawpy#im-getting-deadlocks-when-using-multiprocessing-on-linux for more information.",
5151
RuntimeWarning,
52-
stacklevel=3
52+
stacklevel=2
5353
)
5454
_warned_about_multiprocessing = True
5555
except (RuntimeError, ValueError):

test/test_multiprocessing.py

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def test_multiprocessing_spawn():
6666
pass
6767

6868

69-
def test_multiprocessing_warning_in_fork():
70-
"""Test that a warning is issued when using fork method (if OpenMP is enabled)."""
69+
def test_multiprocessing_warning_detection():
70+
"""Test that the warning detection function exists and works correctly."""
7171
# Skip on Windows
7272
if sys.platform == 'win32':
7373
pytest.skip("Test only relevant on Unix-like systems")
@@ -76,16 +76,11 @@ def test_multiprocessing_warning_in_fork():
7676
if not rawpy.flags or not rawpy.flags.get('OPENMP', False):
7777
pytest.skip("OpenMP not enabled, warning not expected")
7878

79-
# This test can't easily be done in the same process
80-
# because the warning only triggers in child processes
81-
# So we'll just verify the warning code exists
79+
# Verify the warning function exists
8280
from rawpy import _check_multiprocessing_fork
83-
84-
# The function exists
8581
assert _check_multiprocessing_fork is not None
8682

8783
# When called in main process, should not warn
88-
# (we're in MainProcess here)
8984
with warnings.catch_warnings(record=True) as w:
9085
warnings.simplefilter("always")
9186
_check_multiprocessing_fork()
@@ -94,29 +89,11 @@ def test_multiprocessing_warning_in_fork():
9489
assert len(fork_warnings) == 0
9590

9691

97-
def child_process_function_for_warning_test():
98-
"""
99-
This function is meant to be run in a forked child process
100-
to test if the warning is properly issued.
101-
"""
102-
import warnings
103-
with warnings.catch_warnings(record=True) as w:
104-
warnings.simplefilter("always")
105-
import rawpy
106-
# Trigger the check
107-
with rawpy.imread(rawTestPath) as raw:
108-
raw.postprocess(half_size=True)
109-
110-
# Check if warning was issued
111-
fork_warnings = [warning for warning in w if 'fork' in str(warning.message).lower()]
112-
return len(fork_warnings) > 0
113-
114-
11592
if __name__ == '__main__':
11693
print("Testing multiprocessing with spawn method...")
11794
test_multiprocessing_spawn()
11895
print("SUCCESS: No deadlocks with spawn method!")
11996

12097
print("\nTesting warning detection...")
121-
test_multiprocessing_warning_in_fork()
98+
test_multiprocessing_warning_detection()
12299
print("SUCCESS: Warning system working correctly!")

0 commit comments

Comments
 (0)