Skip to content

3.13: Program will crash if importing cv2 in Subinterpreters #133542

@AI-M-BOT

Description

@AI-M-BOT

Crash report

What happened?

Might duplicated

from test.support import interpreters
from time import sleep

def tester():
    from time import sleep
    import ctypes
    print('imported build-in')
    import cv2
    print('imported cv2')
    import sys
    import numpy as np

    for i in range(10000):
        # sys.stdout.write(str(i) + "\n")
        ran_image = np.random.randint(0, 256, size=(416, 416, 3), dtype=np.uint8)
        # sys.stdout.flush()  # Explicitly flush the output buffer
        cv2.imshow(f"aa", ran_image)
        cv2.waitKey(1)
        # sleep(0.001)


t1 = interpreters.create()
# t1.call_in_thread(tester)
# t1.call(tester)
t1.exec('import cv2\nprint("imported cv2")\nfrom time import sleep\nsleep(10)')

for i in range(11):
    print(i)
    print(t1.is_running())
    sleep(1)

Then the interpreters (main and sub) will crash

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Output from running 'python -VV' on the command line:

Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions