<div dir="ltr">Hello,<div><br></div><div>It appears the documentation for http.server is slightly out of date. When I run the following example following the code from <a href="https://docs.python.org/3/library/http.server.html">https://docs.python.org/3/library/http.server.html</a>:</div><div><br></div><div>

<p style="text-align:justify;line-height:22.4px;font-family:"Lucida Grande",Arial,sans-serif;font-size:16px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">The<span> </span><a class="gmail-reference gmail-internal" href="https://docs.python.org/3/library/http.server.html#http.server.SimpleHTTPRequestHandler" title="http.server.SimpleHTTPRequestHandler" style="color:rgb(99,99,187);text-decoration:none"><code class="gmail-xref gmail-py gmail-py-class gmail-docutils gmail-literal gmail-notranslate" style="background-color:transparent;padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;font-weight:normal;border-radius:3px"><span class="gmail-pre" style="hyphens: none;">SimpleHTTPRequestHandler</span></code></a><span> </span>class can be used in the following manner in order to create a very basic webserver serving files relative to the current directory:</p><div class="gmail-highlight-python3 gmail-notranslate" style="font-family:"Lucida Grande",Arial,sans-serif;font-size:16px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><div class="gmail-highlight" style="background:rgb(238,255,204)"><pre style="overflow:auto hidden;padding:5px;background-color:rgb(238,255,204);color:rgb(51,51,51);line-height:18.528px;border:1px solid rgb(170,204,153);font-family:monospace,sans-serif;font-size:15.44px;border-radius:3px"><span></span><span class="gmail-kn" style="color:rgb(0,112,32);font-weight:bold">import</span> <span class="gmail-nn" style="color:rgb(14,132,181);font-weight:bold">http.server</span>
<span class="gmail-kn" style="color:rgb(0,112,32);font-weight:bold">import</span> <span class="gmail-nn" style="color:rgb(14,132,181);font-weight:bold">socketserver</span>

<span class="gmail-n">PORT</span> <span class="gmail-o" style="color:rgb(102,102,102)">=</span> <span class="gmail-mi" style="color:rgb(32,128,80)">8000</span>

<span class="gmail-n">Handler</span> <span class="gmail-o" style="color:rgb(102,102,102)">=</span> <span class="gmail-n">http</span><span class="gmail-o" style="color:rgb(102,102,102)">.</span><span class="gmail-n">server</span><span class="gmail-o" style="color:rgb(102,102,102)">.</span><span class="gmail-n">SimpleHTTPRequestHandler</span>

<span class="gmail-k" style="color:rgb(0,112,32);font-weight:bold">with</span> <span class="gmail-n">socketserver</span><span class="gmail-o" style="color:rgb(102,102,102)">.</span><span class="gmail-n">TCPServer</span><span class="gmail-p">((</span><span class="gmail-s2" style="color:rgb(64,112,160)">""</span><span class="gmail-p">,</span> <span class="gmail-n">PORT</span><span class="gmail-p">),</span> <span class="gmail-n">Handler</span><span class="gmail-p">)</span> <span class="gmail-k" style="color:rgb(0,112,32);font-weight:bold">as</span> <span class="gmail-n">httpd</span><span class="gmail-p">:</span>
    <span class="gmail-nb" style="color:rgb(0,112,32)">print</span><span class="gmail-p">(</span><span class="gmail-s2" style="color:rgb(64,112,160)">"serving at port"</span><span class="gmail-p">,</span> <span class="gmail-n">PORT</span><span class="gmail-p">)</span>
    <span class="gmail-n">httpd</span><span class="gmail-o" style="color:rgb(102,102,102)">.</span><span class="gmail-n">serve_forever</span><span class="gmail-p">()</span>
</pre></div></div><p id="gmail-http-server-cli" style="text-align:justify;line-height:22.4px;font-family:"Lucida Grande",Arial,sans-serif;font-size:16px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><a class="gmail-reference gmail-internal" href="https://docs.python.org/3/library/http.server.html#module-http.server" title="http.server: HTTP server and request handlers." style="color:rgb(99,99,187);text-decoration:none"><code class="gmail-xref gmail-py gmail-py-mod gmail-docutils gmail-literal gmail-notranslate" style="background-color:transparent;padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;font-weight:normal;border-radius:3px"><span class="gmail-pre" style="hyphens: none;">http.server</span></code></a><span> </span>can also be invoked directly using the<span> </span><a class="gmail-reference gmail-internal" href="https://docs.python.org/3/using/cmdline.html#cmdoption-m" style="color:rgb(99,99,187);text-decoration:none"><code class="gmail-xref gmail-std gmail-std-option gmail-docutils gmail-literal gmail-notranslate" style="background-color:transparent;padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;font-weight:normal;border-radius:3px"><span class="gmail-pre" style="hyphens: none;">-m</span></code></a><span> </span>switch of the interpreter with a<span> </span><code class="gmail-docutils gmail-literal gmail-notranslate" style="background-color:rgb(236,240,243);padding:0px 1px;font-size:15.44px;font-family:monospace,sans-serif;border-radius:3px"><span class="gmail-pre" style="hyphens: none;">port</span><span> </span><span class="gmail-pre" style="hyphens: none;">number</span></code><span> </span>argument. Similar to the previous example, this serves files relative to the current directory:</p><div class="gmail-highlight-python3 gmail-notranslate" style="font-family:"Lucida Grande",Arial,sans-serif;font-size:16px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><div class="gmail-highlight" style="background:rgb(238,255,204)"><pre style="overflow:auto hidden;padding:5px;background-color:rgb(238,255,204);color:rgb(51,51,51);line-height:18.528px;border:1px solid rgb(170,204,153);font-family:monospace,sans-serif;font-size:15.44px;border-radius:3px"><span></span><span class="gmail-n">python</span> <span class="gmail-o" style="color:rgb(102,102,102)">-</span><span class="gmail-n">m</span> <span class="gmail-n">http</span><span class="gmail-o" style="color:rgb(102,102,102)">.</span><span class="gmail-n">server</span> <span class="gmail-mi" style="color:rgb(32,128,80)">8000</span></pre></div></div>

<div><br></div><div>It silently exits. Removing the with and not calling __enter__ or __exit__, however, does appear to work fine.</div><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Thanks!</div><div><br></div>Tanner<div>5079938498</div></div></div></div></div></div>
</div></div>