Python tornado, 在Linux下, 是实现了Epoll模型, 还是会使用Linux的Epoll ?

查看:126
本文介绍了Python tornado, 在Linux下, 是实现了Epoll模型, 还是会使用Linux的Epoll ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

实际现象

  • 想弄清楚tornado的Epoll

预期现象

上下文环境

  • 产品版本: Tornado最新

  • 操作系统: Linux

  • Python 2.7.x

解决方案

可以去看tornadoioloop模块。里面有说明

...
class IOLoop(Configurable):
    """A level-triggered I/O loop.
    We use `epoll` (Linux) or `kqueue` (BSD and Mac OS X) if they
    are available, or else we fall back on select(). If you are
    implementing a system that needs to handle thousands of
    simultaneous connections, you should use a system that supports
    either `epoll` or `kqueue`.
...

Linux系统中用epoll,BSDMac OS Xkqueue,其他系统中用select

使用的是python标准库中的select模块。实际上select模块也只是对系统的select的调用,并没有自己实现。

想深入研究的话可以看源码


感谢 @依云 的补充。
python标准库中的select模块是对系统各种I/O复用方案的封装。

>>> import platform
>>> platform.linux_distribution()
('Red Hat Enterprise Linux Server', '6.5', 'Santiago')
>>> import select
>>> dir(select)
['EPOLLERR', 'EPOLLET', 'EPOLLHUP', 'EPOLLIN', 'EPOLLMSG', 'EPOLLONESHOT', 'EPOLLOUT',         
'EPOLLPRI', 'EPOLLRDBAND', 'EPOLLRDNORM', 'EPOLLWRBAND', 'EPOLLWRNORM', 'PIPE_BUF', 
'POLLERR', 'POLLHUP', 'POLLIN', 'POLLMSG', 'POLLNVAL', 'POLLOUT', 'POLLPRI', 'POLLRDBAND', 
'POLLRDNORM', 'POLLWRBAND', 'POLLWRNORM', '__doc__', '__file__', '__name__', 
'__package__', 'epoll', 'error', 'poll', 'select']

这篇关于Python tornado, 在Linux下, 是实现了Epoll模型, 还是会使用Linux的Epoll ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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