【问题标题】:What is the python equivalent of g_log_set_handler when using GLib from python从 python 使用 GLib 时,g_log_set_handler 的 python 等效项是什么
【发布时间】:2013-09-20 13:49:38
【问题描述】:

我想在我的 python glib 项目中设置日志级别。因此,当通过 gi.repository 从 python 使用 GLib 时,我正在寻找 g_log_set_handler() 等效项。

但似乎缺少预期的GLib.log_set_handler 功能。这是我的 python shell 的示例输出:

~$ python
Python 2.7.3 (default, Apr 10 2013, 06:20:15) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from gi.repository import GLib 
>>> GLib.log_set_fatal_mask
<function log_set_fatal_mask at 0x2a7b668> 
>>> GLib.log_set_handler
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/gi/module.py", line 316, in __getattr__
    attr = super(DynamicGLibModule, self).__getattr__(name)
  File "/usr/lib/python2.7/dist-packages/gi/module.py", line 243, in __getattr__
     return getattr(self._introspection_module, name)
  File "/usr/lib/python2.7/dist-packages/gi/module.py", line 105, in __getattr__
    self.__name__, name))
  AttributeError: 'gi.repository.GLib' object has no attribute 'log_set_handler'
>>> 

可以看到,从自省存储库中找到了 GLib,并且存在 log_set_fatal_mask 函数(相当于g_log_set_fatal_mask)。但是找不到log_set_handler。

为什么会这样?如何在 python 中正确设置我的日志级别?

【问题讨论】:

    标签: python glib pygobject gobject gobject-introspection


    【解决方案1】:

    我发现这目前是不可能的,并且 gobject-introspection 或 glib 中存在一个已知错误,因为 g_log_set_handler 不可绑定。

    见: https://bugzilla.gnome.org/show_bug.cgi?id=670507

    【讨论】:

    • 线程如何绑定,因为所有g_thread_create/g_thread_new调用都需要一个函数指针
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-13
    • 1970-01-01
    • 2017-01-27
    • 1970-01-01
    相关资源
    最近更新 更多