如何从 Python 创建 glib.Source?
我想集成一些 asyncore.dispatcher
实例放入 GLib 的 默认主上下文。
我想我可以创建一个 自定义GSource
能够检测asyncore.socket_map
。 CI 相信这是通过创建必要的 GSourceFuncs
这可能涉及对 select 的廉价且非阻塞调用,然后使用 asyncore.read、.write 和朋友来处理它们。
如何从 Python 中实际创建 GSource? glib.Source 类未记录,并且已尝试以交互方式使用该类徒劳的。
是否有其他方法允许我处理 asyncore
模块而不诉诸超时(或任何危及潜在吞吐量和 CPU 使用率的行为)?
I want to integrate some asyncore.dispatcher
instances into GLib's default main context.
I figure I can create a custom GSource
that's able to detect event readiness on the various sockets in asyncore.socket_map
. From C I believe this is done by creating the necessary GSourceFuncs
which could involve cheap and non-blocking calls to select, and then handling them using asyncore.read, .write and friends.
How do I actually create a GSource from Python? The class glib.Source is undocumented, and attempts to use the class interactively have been in vain.
Is there some other method that allows me to handled socket events in the asyncore
module without resorting to timeouts (or anything that endangers potential throughput and CPU usage)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
glib.io_add_watch 做到了(在主循环中添加对 fd 的监视):
http://library.gnome.org/devel/pygobject/2.26/glib-functions.html#function-glib--io-add-watch
glib.io_add_watch does it (add a watch over a fd to the main loop):
http://library.gnome.org/devel/pygobject/2.26/glib-functions.html#function-glib--io-add-watch
下面显示了一种将调度程序与 glib 循环集成的简单方法,非常简单:
An easy way to integrate a dispatcher with a glib loop is shown, very simplified, below: