推荐学习书目
› 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 · 5589 views
    This topic created in 890 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
    PTLin
    May 30, 2024
    1
    sbldehanhan
    sbldehanhan
    OP
    May 30, 2024
    3
    @PTLin #1 linux 上设置了这个属性,也会报:OSError: [Errno 98] Address already in use 。Linux 用不了这个属性?
    sbldehanhan
    sbldehanhan
    OP
    May 30, 2024
    4
    @paopjian #2 嗯,好像还真是 windows 独有。
    PTLin
    PTLin
    May 30, 2024
    5
    @sbldehanhan 忘说了,下面还有一个 SO_REUSEPORT
    zzhaolei
    zzhaolei
    May 30, 2024
    6
    SO_REUSEADDR 和 SO_REUSEPORT ,据说微信用的也是这一套,一个端口多个进程提供服务
    sbldehanhan
    sbldehanhan
    OP
    May 30, 2024
    7
    @PTLin #5 确实可以。Linux 上 PORT 也需要设置一下才行。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1935 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 08:11 · PVG 16:11 · LAX 00:11 · JFK 03:11
    ♥ Do have faith in what you're doing.