擅长:python、mysql、java
<p>SocketServer库使用一些奇怪的方式来处理继承的属性(由于使用了旧样式的类而猜测)。如果创建服务器并列出其受保护的属性,则会看到:</p>
<pre><code>In [4]: server = SocketServer.TCPServer(('127.0.0.1',8000),Handler)
In [5]: server._
server._BaseServer__is_shut_down
server.__init__
server._BaseServer__shutdown_request
server.__module__
server.__doc__
server._handle_request_nonblock
</code></pre>
<p>如果您只是在请求处理程序中添加以下内容:</p>
<pre><code>self.server._BaseServer__shutdown_request = True
</code></pre>
<p>服务器将关闭。这与调用<code>server.shutdown()</code>一样,只是不需要等待(并使主线程死锁)直到它关闭。</p>