Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tornado源码阅读之后 #4

Open
BingLau7 opened this issue Sep 27, 2016 · 0 comments
Open

Tornado源码阅读之后 #4

BingLau7 opened this issue Sep 27, 2016 · 0 comments

Comments

@BingLau7
Copy link
Owner

大概是上个星期将Tornado的源码大概读了一遍,有这么几篇文章值得参考:

主要仔细读的就tcpsever.py, tcpclient.py, httpclient.py, httpserver.py, web.py, ioloop.py

所谓Tornado的高并发其实是epoll/kqueue的封装,对读写进行事件的封装。在全局仅有一个的IOLoop的实例中进行死循环来等待请求发送,这其实主要是避免了IO(网络连接)的等待,而我们在等到请求之后会执行add_handler方法,这其中其实就是我们在Application中所传入的类,这里面类使用了__call__进行包装,从而可以达到调用其类本身就可以调用其中的RequestHandler的对应方法_execute(), 这里面就是处理了我们的请求,并根据请求的方法分配到我们实现的子类自己所实现的get, post方法等,其中检查xsrf等也是在这里面开始进行。

其实这次阅读还是有一些没有深入的地方,例如iostream.py中对于数据流的处理,例如各种util也没有详细阅读。

下次计划准备阅读Flask及其相应的代码,毕竟在Python框架里面,我对这两个框架是最为熟悉的了,也可以与现在阅读的Tornado做一个横向对比。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant