Skip to content

Commit

Permalink
Default callback no longer needs gil
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Apr 24, 2024
1 parent 6806d74 commit 7042f09
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
11 changes: 0 additions & 11 deletions av/logging.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging
from threading import Lock
from typing import Any, Callable

PANIC: int
Expand Down Expand Up @@ -32,12 +30,3 @@ class Capture:
value: Exception | None,
traceback: Callable[..., Any] | None,
) -> None: ...

level_threshold: int
skip_repeated: bool
skip_lock: Lock
last_log: tuple[int, str, str] | None
skip_count: int
last_error: tuple[int, str, str] | None
global_captures: list[list[tuple[int, str, str]]]
thread_captures: dict[int, list[tuple[int, str, str]]]
14 changes: 9 additions & 5 deletions av/logging.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import sys
from threading import Lock, get_ident

# Library levels.
# QUIET = lib.AV_LOG_QUIET # -8; not really a level.
PANIC = lib.AV_LOG_PANIC # 0
FATAL = lib.AV_LOG_FATAL # 8
ERROR = lib.AV_LOG_ERROR
Expand Down Expand Up @@ -110,8 +109,12 @@ def set_level(level):
"""
global level_threshold

if level is None or type(level) is int:
if level is None:
level_threshold = level
lib.av_log_set_callback(nolog_callback)
elif type(level) is int:
level_threshold = level
lib.av_log_set_callback(log_callback)
else:
raise ValueError("level must be: int | None")

Expand Down Expand Up @@ -288,8 +291,6 @@ cdef void log_callback(void *ptr, int level, const char *format, lib.va_list arg
return

with gil:
if level_threshold is None:
return
if level > level_threshold and level != lib.AV_LOG_ERROR:
return

Expand All @@ -314,4 +315,7 @@ cdef void log_callback(void *ptr, int level, const char *format, lib.va_list arg
lib.PyErr_Display(exc, type_, tb)


lib.av_log_set_callback(log_callback)
cdef void nolog_callback(void *ptr, int level, const char *format, lib.va_list args) noexcept nogil:
pass

lib.av_log_set_callback(nolog_callback)

0 comments on commit 7042f09

Please sign in to comment.