imdecode jpeg2000 segfault or deadlock in multithreading
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 5.4k
- Fork
- 1k
- Merge medio
- 22h 17m
- PR unite (30g)
- 3
Descrizione
Expected behaviour
In the main thread, it works well as written in the example bellow:
import multiprocessing.pool
import cv2
import numpy as np
import tqdm
img = np.random.randint(0, 65335, (1024, 1024), dtype=np.uint16)
_, img_data = cv2.imencode(".jp2", img)
n = 100
def read(i):
image = cv2.imdecode(buffer, cv2.IMREAD_ANYDEPTH | cv2.IMREAD_GRAYSCALE)
list(tqdm.tqdm(map(read, range(n)), total=n, desc="main thread main process"))
with multiprocessing.pool.Pool() as pool:
list(tqdm.tqdm(pool.imap_unordered(read, range(n)), total=n, desc="main thread child process"))
Actual behaviour
But in a thread, it is all broken!
import multiprocessing.pool
import cv2
import numpy as np
import tqdm
img = np.random.randint(0, 65335, (1024, 1024), dtype=np.uint16)
_, img_data = cv2.imencode(".jp2", img)
n = 100
def read(i):
image = cv2.imdecode(buffer, cv2.IMREAD_ANYDEPTH | cv2.IMREAD_GRAYSCALE)
with multiprocessing.pool.ThreadPool() as pool:
list(tqdm.tqdm(pool.imap_unordered(read, range(n)), total=n, desc="child thread main process"))
When the code does not freeze by itself, an interrupt with ctrl+c leads allways to a segfault. Unlike the threadless example.
Steps to reproduce
- Tested on Debian, Ubuntu and Mint
- Version 4.9.0 of opencv-contrib-python-headless
- Tested on python 3.9, 3.10, 3.11 and 3.12
- architecture x86
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con il riproduttore Python ThreadPool fornito e confrontalo con il caso multiprocessing Pool negli ambienti Python e basati su Debian elencati. Verifica la configurazione del buffer e osserva se la decodifica JPEG2000 viene completata in sicurezza con thread concorrenti; il lavoro è completato quando non si verificano deadlock o segfault e la decodifica riesce nelle chiamate ripetute.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100