docs: add multiprocessing fork safety warning (fixes #1166)#1225
Open
molhamfetnah wants to merge 2 commits intoopencv:4.xfrom
Open
docs: add multiprocessing fork safety warning (fixes #1166)#1225molhamfetnah wants to merge 2 commits intoopencv:4.xfrom
molhamfetnah wants to merge 2 commits intoopencv:4.xfrom
Conversation
- Changed install_requires to specify minimum numpy versions per Python version: - Python 3.9-3.12: numpy>=2.0.2 - Python 3.13: numpy>=2.1.3 - Python 3.14+: numpy>=2.3.0 - This fixes NumPy 2.x ABI compatibility issue where wheels compiled against NumPy 1.x fail at runtime with NumPy 2.x Fixes opencv#1201
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: opencv#1166
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fork()cv2.setNumThreads(0)Technical Context
This is a known limitation of OpenCV, not a bug in the Python bindings. The "corrupted double-linked list" error is caused by:
fork()The root fix would require adding
pthread_atforkhandlers in OpenCV's C++ core (opencv/opencv) to reset internal state on fork. This packaging-only repo cannot implement that fix.Workarounds (documented)
Users should either:
multiprocessing.set_start_method('spawn')cv2.setNumThreads(0)before using cv2This is the same workaround recommended in other related issues (#5150, #1007).
Related Issues