hazard
V2EX  ›  问与答

StreamRequestHandler 实例对象中对 self.rfile,self.wfile 的读写操作和对 self.connect 进行 recv,write 操作有何区别?

  •  
  •   hazard · Oct 29, 2016 · 4710 views
    This topic created in 3507 days ago, the information mentioned may be changed or developed.
    版本:Python2.7 谢谢解答!
    3 replies    2016-10-30 01:48:30 +08:00
    sivacohan
        1
    sivacohan  
    PRO
       Oct 30, 2016 via Android
    rfile 和 wfile 都是一个封装。
    rfile 可以试用 readline
    wfile 写入没缓冲区

    猜测,如果都是用 byte 差别不大。如果处理的是文本型数据, rfile , wfile 能方便点。
    ldbC5uTBj11yaeh5
        2
    ldbC5uTBj11yaeh5  
       Oct 30, 2016 via Android
    大兄弟, python 的那套传统标准库都是玩具级的,如果不是工作任务不值得深究。

    推荐你看新一点的 asyncio 或 gevent/tornado 。
    sivacohan
        3
    sivacohan  
    PRO
       Oct 30, 2016
    我猜测没有错。
    关于 rfile 和 wfile 都是通过 makefile 来实现的。
    https://hg.python.org/cpython/file/2.7/Lib/SocketServer.py#l702

    makefile 在这里
    https://hg.python.org/cpython/file/tip/Lib/socket.py#l218

    而在 tcpserver 里面的 connection 对象,实际上就是一个 socket
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3007 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 07:10 · PVG 15:10 · LAX 00:10 · JFK 03:10
    ♥ Do have faith in what you're doing.