python - Python 异常在 Glib/DBUS 循环中发生时不会传播/打印
问题描述
当错误/异常(例如 NameError,因为我打错了变量名)发生在notification_filter
-- 错误/异常信息似乎没有被传播(或被静默捕获)。
一个简单的例子:
import dbus
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib
def notification_filter(bus, message):
raise Exception("This exception is never propagated/printed")
if __name__ == "__main__":
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_match_string_non_blocking("eavesdrop=true, interface='org.freedesktop.Notifications', member='Notify'")
bus.add_message_filter(notification_filter)
mainloop = GLib.MainLoop()
mainloop.run()
发生错误/异常时如何打印/记录信息?
解决方案
推荐阅读
- nginx - 图像处理 - 如何从 lua 脚本启用对 openresty 服务器的 avif 支持
- continuous-integration - 默认服务帐户的 k3s gitlab ci-cd 问题
- java - 是否可以防止 WebView 或任何 View 被破坏?
- sql-server - 替换 CustomerID 字段中的单个数字 SQL Server
- c++ - 找到重叠和下采样散点图
- python - 有没有办法用 PyQt5 捕捉按钮上的悬停事件信号?
- android - 在Android中设置密码时如何在锁定屏幕上显示活动
- python - 处理列表时如何在火花中找到字符串中的索引?
- javascript - useEffect:状态更新后不渲染
- scala - 将使用访问者的 Traversable 迁移到 Scala 2.13 中的 Iterable