berarr
This commit is contained in:
38
cht/app.py
38
cht/app.py
@@ -1,5 +1,7 @@
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "4.0")
|
||||
@@ -25,14 +27,40 @@ class ChtApp(Adw.Application):
|
||||
win.present()
|
||||
|
||||
|
||||
def _suppress_egl_warnings(domain, level, message, user_data):
|
||||
if b"eglExportDMABUFImage" in message:
|
||||
return
|
||||
GLib.log_default_handler(domain, level, message, user_data)
|
||||
_STDERR_SKIP = [b"eglExportDMABUFImage"]
|
||||
|
||||
|
||||
def _filter_stderr():
|
||||
"""Redirect fd 2 through a pipe; drop lines matching _STDERR_SKIP."""
|
||||
real_stderr_fd = os.dup(2)
|
||||
real_stderr = os.fdopen(real_stderr_fd, "wb", buffering=0)
|
||||
r_fd, w_fd = os.pipe()
|
||||
os.dup2(w_fd, 2)
|
||||
os.close(w_fd)
|
||||
|
||||
def _pump():
|
||||
with os.fdopen(r_fd, "rb", buffering=0) as pipe:
|
||||
buf = b""
|
||||
while True:
|
||||
chunk = pipe.read(4096)
|
||||
if not chunk:
|
||||
break
|
||||
buf += chunk
|
||||
while b"\n" in buf:
|
||||
line, buf = buf.split(b"\n", 1)
|
||||
if line.strip() and not any(skip in line for skip in _STDERR_SKIP):
|
||||
real_stderr.write(line + b"\n")
|
||||
real_stderr.flush()
|
||||
if buf:
|
||||
real_stderr.write(buf)
|
||||
real_stderr.flush()
|
||||
|
||||
t = threading.Thread(target=_pump, daemon=True, name="stderr_filter")
|
||||
t.start()
|
||||
|
||||
|
||||
def main():
|
||||
GLib.log_set_handler("Gdk", GLib.LogLevelFlags.LEVEL_WARNING, _suppress_egl_warnings, None)
|
||||
_filter_stderr()
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
format="%(asctime)s %(levelname)-7s %(name)s: %(message)s",
|
||||
|
||||
Reference in New Issue
Block a user