【发布时间】:2019-02-16 03:17:44
【问题描述】:
据我从可用文档中得知,GLib.io_add_watch() 应该注册一个在 IOChannel 上发生条件时要调用的函数,并且 callback function 应该作为第一个接收所述 IOChannel争论。太好了,除了它没有。 GLib 将一个完全不同的 IOChannel 对象传递给回调。为什么?
换句话说,为什么这段代码会产生 AssertionError?
#!/usr/bin/env python3
import gi
from gi.repository import GLib
_, _, fd, _ = GLib.spawn_async(['/bin/echo', 'hello'], standard_output=True)
channel = GLib.IOChannel.unix_new(fd)
def on_read(callback_channel, condition):
assert callback_channel is channel
GLib.io_add_watch(channel, GLib.PRIORITY_DEFAULT, GLib.IO_IN, on_read)
GLib.MainLoop().run()
【问题讨论】: