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
Expected behaviour
In the main thread, it works well as written in the example bellow:
Actual behaviour
But in a thread, it is all broken!
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