Hacker News new | past | comments | ask | show | jobs | submit login

How does this differ from the stdlib approach?

    python -m http.server 8080 --bind 127.0.0.1 --directory your_directory



May I direct your attention to the second sentence of my post?

It fixes an issue in the Python built-in HTTP server that causes it to hang under concurrent connections.

First, run the built-in Python web server:

  [term1]$ python -m SimpleHTTPServer 8080
Then connect to it with a client that doesn't immediately send a request, such as `netcat`. This simulates the behavior of modern browsers, which seem to set up a pool of pre-established connections.

  [term2]$ nc localhost 8080
Now try to get a page from the server via Curl (or wget, etc). It will hang after sending the request, because the server's single thread is trying to serve the idle connection.

  [term3]$ curl -v http://127.0.0.1:8080
  *   Trying 127.0.0.1:8080...
  * TCP_NODELAY set
  * Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
  > GET / HTTP/1.1
  > Host: 127.0.0.1:8080
  > User-Agent: curl/7.68.0
  > Accept: */*
  > 
In real life, the behavior I saw was that I'd try to connect to the server with Chrome and it would hang after the pages had partially loaded.


I totally missed that! Thanks for the additional detail.

This issue appears to have been fixed: https://github.com/python/cpython/issues/75820


I think this is a problem that's long been fixed; I tested your command and it seems to work as expected for me in Python 3.10 anyway. And I've been using the "python -mhttp.server" frequently for years, and never experienced any of these problems.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: