Skip to content

Commit 4e4505a

Browse files
committed
docs: add multiprocessing fork safety warning
Add documentation about OpenCV not being fork-safe and the 'corrupted double-linked list' issue that can occur when using cv2 functions after fork(). Fixes: #1166
1 parent 19a9c9b commit 4e4505a

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

scripts/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
"""
2+
OpenCV Python bindings
3+
4+
This module provides Python bindings for OpenCV.
5+
6+
Important notes for multiprocessing:
7+
- OpenCV is not fork-safe. Using cv2 functions after fork() can cause
8+
"corrupted double-linked list" errors and memory corruption.
9+
- If you use multiprocessing with fork (the default on Linux/macOS),
10+
either:
11+
1. Use spawn mode: multiprocessing.set_start_method('spawn')
12+
2. Call cv2.setNumThreads(0) in each worker before using cv2
13+
- See: https://github.com/opencv/opencv-python/issues/1166
14+
"""
15+
16+
import os
17+
import sys
18+
import warnings
19+
120
PYTHON_EXTENSIONS_PATHS = [
221
LOADER_DIR
322
] + PYTHON_EXTENSIONS_PATHS
@@ -21,4 +40,4 @@
2140
if sys.platform.startswith("linux") and ci_and_not_headless:
2241
os.environ["QT_QPA_FONTDIR"] = os.path.join(
2342
os.path.dirname(os.path.abspath(__file__)), "qt", "fonts"
24-
)
43+
)

0 commit comments

Comments
 (0)