Skip to content

Release the GIL during slow setup calls - #2520

Merged
WyattBlue merged 1 commit into
masterfrom
release-gil-setup
Nov 18, 2026
Merged

WyattBlue merged 1 commit into
masterfrom
release-gil-setup

Conversation

@WyattBlue

Copy link
Copy Markdown
Member

Follow-up to #2518, for the other slow FFmpeg calls that held the GIL:

  • FilterContext.init() (avfilter_init_str() / avfilter_init_dict()) and Graph.configure() (avfilter_graph_config()). Some filters do heavy work at init, such as whisper loading its model or dnn_* loading a network.
  • enumerate_input_devices() / enumerate_output_devices(), including the list_devices fallback, which probe drivers. FFmpeg's log callback reacquires the GIL on the same thread, so avlogging.Capture still collects the device list.
  • The CUDA device (av_hwdevice_ctx_create()) and frame pool (av_hwframe_ctx_init()) behind VideoFrame.from_dlpack().

Listing avfoundation devices on macOS, with another thread ticking every 1 ms:

call longest pause
before 234.9 ms 235.2 ms
after 235.2 ms 1.4 ms

Filter init and graph configuration can load models (whisper, dnn_*),
device listing probes drivers, and creating a CUDA device or frame pool
can take hundreds of milliseconds. All of these held the GIL, stopping
every other Python thread.
@WyattBlue
WyattBlue merged commit 1cab73e into master Nov 18, 2026
10 checks passed
@WyattBlue
WyattBlue deleted the release-gil-setup branch November 18, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant