Python 3 的事件循环实现? [英] Event loop implementation for Python 3?

查看:19
本文介绍了Python 3 的事件循环实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道可用于 Python 3 的事件循环库(或绑定)吗?如果它只适用于 UNIX 系统也没关系,尽管我更喜欢适用于 Windows 的系统.

Does anyone know of an event loop library (or bindings) available for Python 3? It's okay if it only does UNIX systems, though I would prefer something that does Windows as well.

ETA:我意识到编写事件循环系统并不难.但是,我不想重新发明轮子(我们现在仍然鼓励不要这样做,对吧?;-))

ETA: I realize that it is not terribly difficult to write an event loop system. However, I don't want to reinvent the wheel (we are still encouraging not doing so these days, right? ;-))

这是为服务器应用程序计划的,所以显然我想要一些不与 GUI 小部件工具包或其他东西绑定的东西.

This is planned for a server application, so obviously I'd want something that isn't tied to a GUI widget toolkit or something.

如果答案是不,没有"(可能;我肯定找不到),那么我很可能会为 Python 3 为 libev 创建一个绑定.

If the answer is "Nope, there isn't one" (probably; I sure as heck can't find one) then I will most likely create a binding for Python 3 for libev.

推荐答案

我建议如下:

while True:
    while queue:
        queue.pop()()

但是,为了使该功能起作用,您需要让事件系统将可调用事件放入队列中.

For that to work, however, you need to have the event system put callable events onto the queue.

(如果您对 specific 绑定到 specific 框架更感兴趣,例如 GTK、Qt、WxWidgets、NCurses、Cocoa、Winforms 等等,那么请说那个!).

(If you are more interested in a specific binding to a specific framework, such as GTK, Qt, WxWidgets, NCurses, Cocoa, Winforms, whatever, then say that!).

这篇关于Python 3 的事件循环实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆