-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logging framework can lead to deadlocks #751
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This is still an issue. |
+1 that this should be opt-in instead of opt-out by default. It would also be very useful to provide some functionality to suppress all log messages by passing a no-op callback rather than relying on log levels. I'm not very familiar with Cython, however I see the logger callback is marked as Would it make sense to call Another potential point of concern is if the thread is destroyed mid-way through callback execution - this could potentially poison the GIL state, or even the |
You have some excellent question, but I'll be honest we're reaching the limits of my Cython knowledge. Below are some thoughts: Log verbosity
I don't understand the value of filtering messages inside PyAV at all, it would seem a lot more efficient for av.logging.set_level to directly call av_log_set_level and let FFmpeg do the filtering itself so unwanted messages don't even reach PyAV. @mikeboers ? EDIT: I was wrong. We could also most likely default to AV_LOG_WARNING since that is in effect the only thing we send through to the Python logger by default (unless I'm mistaken..). Judging by our users' feedback if anything they want less logging not more. Opt-in vs opt-outI'd also be in favor of making the logging framework opt-in, but there is one very useful usecase: it's what enables us to raise sensible exceptions. If you have a close look the logging framework captures error messages, which can then be used by Based on this my impression is that we probably do need a logging callback to capture errors, but for the rest we could probably stay out of the way and just hand off to FFmpeg's default callback. |
Here's another finding. I tried to cut down the cdef void log_callback(void *ptr, int level, const char *format, lib.va_list args) nogil:
with gil:
pass So in short there doesn't seem to be any safe way of running Python in the log callback. My gut feeling at this stage would be:
|
Is there any way to repro this on x86 or does it have to be on an RPi? I had a look at the generated Cython code and it seems to generate an Ensure/Release pair as expected, and you can call it multiple times from the same thread, which makes this hang even more puzzling to be honest. I don't know if the driver source code is public or not, so there might be some threads created there, but interestingly, I don't see the codec itself creating any threads: Are you able to see any log output from that when this happens? What happens if you check For the related issue I had where the interpreter hung on exit, |
I am reproducing this using the same code as in #909, on Debian, x86_64. |
Oh sorry I meant specifically in the case where it hangs on |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Still very much an issue |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This is still an issue. It even causes a deadlock if logging is disabled, see aiortc/aiortc#734 (comment) |
shall this issue be reopened? |
Yes absolutely! |
I've fixed this in master now. The logging is now disabled by default (the callback is a no-op). import av
# No logs whatso ever (no GIL calls)
av.logging.set_level(None)
# You can change the log level on the fly.
# Set to the old default (detailed error messages).
av.logging.set_level(av.logging.VERBOSE) |
Here's a basic test import av
print('Starting test.')
container = av.open('example.mp4')
container.streams.video[0].thread_type = 'AUTO'
# Have to decode at least one frame to trigger the bug.
next(container.decode(video=0))
print('Test complete.') av 12.0.0 locks up 1/2 of the time |
Currently PyAV wires up FFmpeg's logging so that messages are sent to Python's traditional loggers instead of going straight to stderr.
One such example is simply trying to open a
CodecContext
for theh264_omx
(hardware accelerated H264) codec on a RaspberryPi.This code will hang forever on the
codec.open()
call. Setting the environment variablePYAV_LOGGING=off
completely solves the issue.@mikeboers I am starting to wonder whether the logging support should be opt-in instead of opt-out, any thoughts on this?
The text was updated successfully, but these errors were encountered: