推荐学习书目
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
fghjghf
V2EX  ›  Python

python3 的 EPOLLHUP 是怎么触发的?

  •  
  •   fghjghf · May 27, 2019 · 3290 views
    This topic created in 2551 days ago, the information mentioned may be changed or developed.
    如题。对端发送 close 关闭 socket,服务端的 EPOLLHUP 为啥不执行呢?
    前提:没有被 IN/OUT 覆盖,我是把它写在 if 判断的第一个位置。我打印了 event 的值,发现只有 1(in)、4(out)、5( in | out),并没有发现 EPOLLHUP 16 的迹象。
    dalao 们,有遇到过么,麻烦指点下
    8 replies    2019-05-29 14:57:35 +08:00
    lcdtyph
        1
    lcdtyph  
       May 27, 2019 via iPhone
    对端 close 的话 epoll 返回 EPOLLRDHUP
    EPOLLHUP 是对端 reset 了连接(假设 tcp )
    moxiaowei
        2
    moxiaowei  
       May 27, 2019 via iPhone
    epoll 主动 modify 触发
    fghjghf
        3
    fghjghf  
    OP
       May 27, 2019
    @lcdtyph 这个我知道,按道理是这样的,不过我在 python3.7 里面,就是不触发,哭
    fghjghf
        4
    fghjghf  
    OP
       May 27, 2019
    @moxiaowei 请问具体是如何 modify 的呢,在什么情况下
    mythmgn
        5
    mythmgn  
       May 29, 2019
    没写过 3 的, 但是处理过 py2.7 的, 估计大同小异 可以参考下我的连接池实现代码:

    github.com/baidu/CUP/blob/master/cup/net/async/conn.py 重点是 poll 方法那一块
    mythmgn
        6
    mythmgn  
       May 29, 2019
    @fghjghf

    while not self._stopsign:
    try:
    events = self._epoll.poll(1)
    except IOError as err:
    if err.errno == errno.EINTR:
    return
    raise err
    # log.debug('start to poll')
    for fileno, event in events:
    # if it comes from the listen port, new conn
    if fileno == self._bind_sock.fileno():
    newsock, addr = self._bind_sock.accept()
    self._handle_new_conn(newsock, addr)
    elif event & select.EPOLLIN:
    try:
    self._handle_new_recv(self._fileno2context[fileno])
    except KeyError:
    log.info('socket already closed')
    elif event & select.EPOLLOUT:
    try:
    self._handle_new_send(self._fileno2context[fileno])
    except KeyError:
    log.info('socket already closed')
    elif (event & select.EPOLLHUP) or (event & select.EPOLLERR):
    # FIXME: consider if we need to release net msg resources
    if event & select.EPOLLHUP:
    log.info('--EPOLLHUP--')
    else:
    log.info('--EPOLLERR--')
    try:
    self.cleanup_error_context(
    self._fileno2context[fileno]
    )
    except KeyError:
    log.info('socket already closed')
    mythmgn
        7
    mythmgn  
       May 29, 2019
    @fghjghf V2EX 不知道怎么显示代码, 直接 github 看吧
    fghjghf
        8
    fghjghf  
    OP
       May 29, 2019
    @mythmgn 好的,感谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3761 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 05:05 · PVG 13:05 · LAX 22:05 · JFK 01:05
    ♥ Do have faith in what you're doing.