[docs] http.server silently exists
Tanner Firl
firlx010 at umn.edu
Sat Aug 25 11:55:17 EDT 2018
Hello,
It appears the documentation for http.server is slightly out of date. When
I run the following example following the code from
https://docs.python.org/3/library/http.server.html:
The SimpleHTTPRequestHandler
<https://docs.python.org/3/library/http.server.html#http.server.SimpleHTTPRequestHandler>
class can be used in the following manner in order to create a very basic
webserver serving files relative to the current directory:
import http.serverimport socketserver
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
http.server
<https://docs.python.org/3/library/http.server.html#module-http.server> can
also be invoked directly using the -m
<https://docs.python.org/3/using/cmdline.html#cmdoption-m> switch of the
interpreter with a port number argument. Similar to the previous example,
this serves files relative to the current directory:
python -m http.server 8000
It silently exits. Removing the with and not calling __enter__ or __exit__,
however, does appear to work fine.
Thanks!
Tanner
5079938498
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20180825/c096e7c8/attachment-0001.html>
More information about the docs
mailing list