Event loop implementation for Python 3?

徘徊边缘 提交于 2019-12-19 04:46:58

问题


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: 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? ;-))

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

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.


回答1:


I suggest something like:

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

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

(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!).




回答2:


libev is available for python as pyev module: http://code.google.com/p/pyev/



来源:https://stackoverflow.com/questions/6812397/event-loop-implementation-for-python-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!