关于 epoll 的小小疑问, epoll 在等待事件的过程中会阻塞么 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
veezzz
V2EX    Python

关于 epoll 的小小疑问, epoll 在等待事件的过程中会阻塞么

  •  
  •   veezzz 2015-01-04 16:42:21 +08:00 4215 次点击
    这是一个创建于 3941 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在看tornado的源码,有个RT的疑问

    try: event_pairs = self._impl.poll(poll_timeout) except Exception as e: # Depending on python version and IOLoop implementation, # different exception types may be thrown and there are # two ways EINTR might be signaled: # * e.errno == errno.EINTR # * e.args is like (errno.EINTR, 'Interrupted system call') if errno_from_exception(e) == errno.EINTR: continue else: raise 

    在调用poll方法等待事件的过程中epoll是马上返回还是至少有一个事件后才返回

    5 条回复    2015-01-04 20:14:57 +08:00
    Missex
        1
    Missex  
       2015-01-04 17:23:40 +08:00   1
    epoll是有事件的时候或者超时才返回。
    aszxqw
        2
    aszxqw  
       2015-01-04 17:29:11 +08:00   1
    会。
    dndx
        3
    dndx  
       2015-01-04 17:56:12 +08:00   1
    可以阻塞也可以不阻塞。如果 timeout 是 -1,那么会一直等待直到最少一个 vent available 或者被信号中断。

    如果 timeout 是 0,那么会立刻返回,即使没有可用 event。

    如果 timeout 是其他数字,那么会最多等待这么多秒,除非有至少一个 event available 或者被信号中断。

    http://man7.org/linux/man-pages/man2/epoll_wait.2.html
    zenliver
        4
    zenliver  
       2015-01-04 19:10:19 +08:00   1
    tornado的会, epoll自身可以立刻返回, 参考man
    inevermore
        5
    inevermore  
       2015-01-04 20:14:57 +08:00   1
    常规用法是会的。 而且用epoll的目的是,其他代码不阻塞,仅仅在epoll调用处阻塞。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1178 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 23:53 PVG 07:53 LAX 16:53 JFK 19:53
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86