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
sbldehanhan
V2EX  ›  Python

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

  •  
  •   sbldehanhan · 23 天前 · 1634 次点击

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

    7 条回复    2024-05-30 22:55:33 +08:00
    PTLin
        1
    PTLin  
       23 天前
    sbldehanhan
        3
    sbldehanhan  
    OP
       23 天前
    @PTLin #1 linux 上设置了这个属性,也会报:OSError: [Errno 98] Address already in use 。Linux 用不了这个属性?
    sbldehanhan
        4
    sbldehanhan  
    OP
       23 天前
    @paopjian #2 嗯,好像还真是 windows 独有。
    PTLin
        5
    PTLin  
       23 天前
    @sbldehanhan 忘说了,下面还有一个 SO_REUSEPORT
    zzhaolei
        6
    zzhaolei  
       23 天前
    SO_REUSEADDR 和 SO_REUSEPORT ,据说微信用的也是这一套,一个端口多个进程提供服务
    sbldehanhan
        7
    sbldehanhan  
    OP
       23 天前
    @PTLin #5 确实可以。Linux 上 PORT 也需要设置一下才行。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2055 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 01:30 · PVG 09:30 · LAX 18:30 · JFK 21:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.