Skip to content

Strange problem about memory and numpy.ndarray when using Katna on Windows with Python 3.12 #36

@mimi99528

Description

@mimi99528

Describe the bug
When using Katna's Video class to extract keyframes on Windows with Python 3.12, the process crashes with errors related to:

  1. RuntimeError: CPU dispatcher tracer already initialized
  2. AttributeError: module 'numpy' has no attribute 'ndarray'

These errors occur even with proper virtual memory settings and 64GB physical RAM available. The issue persists despite attempts to:

  • Use if __name__ == "__main__" guard
  • Downgrade Python (tested with 3.10/3.11)
  • Reinstall dependencies (numpy, opencv-python, imagecodecs)

Expected behavior
Keyframe extraction should complete without multiprocessing-related initialization conflicts.


Environment

  • OS: Windows 10/11 (both tested)
  • Python: 3.12.0 (64-bit), 3.10.13 (64-bit)
  • Katna: 1.0.0 (latest pip version)
  • Dependencies:
    • numpy 2.0.1
    • opencv-python 4.8.0.76
    • imagecodecs 2023.7.21

Error logs

Traceback (most recent call last): File "D:\KSFrame\KFramesAnalyzer.py", line 1, in <module> from Katna.video import Video File "D:\Python\Python312\Lib\site-packages\Katna\video.py", line 11, in <module> import numpy as np File "D:\Python\Python312\Lib\site-packages\numpy_init_.py", line 692, in <module> _core.getlimits._register_known_types() File "D:\Python\Python312\Lib\site-packages\numpy_core\getlimits.py", line 236, in _register_known_types float128_ma = MachArLike(ld, ^^^^^^^^^^^^^^ ... [truncated for brevity] AttributeError: module 'numpy' has no attribute 'ndarray'

Code to reproduce

python from Katna.video import Video 
from Katna.writer import KeyFrameDiskWriter
if name == "main": 
    FE = Video() 
    writer = KeyFrameDiskWriter(location="selectedframes")
    FE.extract_video_keyframes(3, "test.mp4", writer) # Crashes here

Potential root cause

  1. Multiprocessing conflict: Katna's internal use of multiprocessing spawns new processes that re-import modules, causing numpy's C-extensions to fail initialization.
  2. NUM_WORKERS limitation: Setting Katna.config.NUM_WORKERS = 1 doesn't fully disable multiprocessing logic in Windows.
  3. Python 3.12 compatibility: Potential incompatibility with numpy 2.x series and C-extension initialization on Windows.

AI used for proper expression

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions