How does gevent know which type of event the registered task is interested in?

44 views
Skip to first unread message

齐辰雄

unread,
Apr 5, 2014, 7:11:31 AM4/5/14
to gev...@googlegroups.com
Hi all,

After learning gevent from documentation and some simple examples, a question emerges in my mind, just as the subject how gevent knows which type of event a registered task is interested in. For example, following most simple code is used usually,

def add(x, y):
    return x + y

greenlet = gevent.spawn(add, 1, 2)


Many other similar example code may be given here to do some disk IO task or network IO task. However, no argument to indicate event type here. From the source code, greenlet.start method just adds such methods to libev event loop as callback function. I'm a bit confuse about this. Could anybody give some explanation and guidance? Thanks!

Regards,
Chenxiong Qi

Fantix King

unread,
Apr 7, 2014, 11:04:53 AM4/7/14
to gev...@googlegroups.com
您好!

greenlet 其实并不参与 libev 相关的事件注册,并且一个 greenlet 也不限制于对单一事件的处理;greenlet 其实只是一种异步任务调度的实现工具,与异步事件并无直接关系。

关于异步事件的注册,您可以参考比如 gevent/socket.py 里 socket 初始化的部分。

--
You received this message because you are subscribed to the Google Groups "gevent: coroutine-based Python network library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gevent+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Fantix King

unread,
Apr 7, 2014, 11:13:58 AM4/7/14
to gev...@googlegroups.com
Whoops, this was intended to be a private reply... anyway here's the English version

Greenlet as the implementation detail of the gevent task scheduler, has nothing to do with the async "events" - let alone limiting the number of event types.

Please find how gevent handles the events in e.g. socket initialization in gevent/socket.py.

BR,
Fantix

Fantix King <fanti...@gmail.com>于2014年4月7日星期一写道:
Reply all
Reply to author
Forward
0 new messages