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

为什么同时启动两个 Python 自带的 http server 不报端口占用呢?

  •  
  •   sbldehanhan · May 30, 2024 · 5103 views
    This topic created in 851 days ago, the information mentioned may be changed or developed.

    在 Windows 上分别在两个 terminal 中运行 python -m http.server ,神奇的是竟然可以同时运行,没有报端口占用,明明都是 8000 端口啊,自己写的代码就不行。咋回事?

    7 replies  •  2024-05-30 22:55:33 +08:00
    PTLin
        1
    PTLin  
       May 30, 2024
    sbldehanhan
        3
    sbldehanhan  
    OP
       May 30, 2024
    @PTLin #1 linux 上设置了这个属性,也会报:OSError: [Errno 98] Address already in use 。Linux 用不了这个属性?
    sbldehanhan
        4
    sbldehanhan  
    OP
       May 30, 2024
    @paopjian #2 嗯,好像还真是 windows 独有。
    PTLin
        5
    PTLin  
       May 30, 2024
    @sbldehanhan 忘说了,下面还有一个 SO_REUSEPORT
    zzhaolei
        6
    zzhaolei  
       May 30, 2024
    SO_REUSEADDR 和 SO_REUSEPORT ,据说微信用的也是这一套,一个端口多个进程提供服务
    sbldehanhan
        7
    sbldehanhan  
    OP
       May 30, 2024
    @PTLin #5 确实可以。Linux 上 PORT 也需要设置一下才行。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   898 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:44 · PVG 03:44 · LAX 12:44 · JFK 15:44
    ♥ Do have faith in what you're doing.