container.close() holds GIL, causing deadlock when combined with pipe
Created by: ninja-
Overview
I have a PyAV stream that writes to output that is a unix pipe (mkfifo). When calling container.close(), libav waits for the other side to finish reading data written to pipe - as it should. Unfortunately, since the pipe consumer is another Python thread, that leads to deadlock during close(), as that thread can never read the last bits of data as container.close() holds the GIL.
The workaround I used is to push PyAV to "multiprocessing" process...
Expected behavior
There should be no GIL hold during calls to demux() or container.close()
Actual behavior
GIL is hold for container.close()
Build report:
Investigation
{{ What you did to isolate the problem. }}
Reproduction
Create a mkfifo file. Create two threads, one reads from the pipe, and other writes to it using PyAV container, and later does PyAV.close() See high chance of GIL deadlock during close()
Versions
- OS: Linux
- PyAV runtime: pip3 latest
- PyAV build:
- FFmpeg:
Research
I have done the following:
-
Checked the PyAV documentation -
Searched on Google -
Searched on Stack Overflow -
Looked through old GitHub issues -
Asked on PyAV Gitter -
... and waited 72 hours for a response.