Python - BaseHTTPServer.HTTPServer 并发和线程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2398144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-04 00:33:58  来源:igfitidea点击:

Python - BaseHTTPServer.HTTPServer Concurrency & Threading

pythonmultithreadinghttpserverbasehttpserversocketserver

提问by Ian

Is there a way to make BaseHTTPServer.HTTPServer be multi-threaded like SocketServer.ThreadingTCPServer?

有没有办法让 BaseHTTPServer.HTTPServer 像 SocketServer.ThreadingTCPServer 一样是多线程的?

回答by Wolph

You can simply use the threading mixin using both of those classes to make it multithread :)

您可以使用这两个类简单地使用线程混合来使其成为多线程:)

It won't help you much in performance though, but it's atleast multithreaded.

虽然它不会对你的性能有太大帮助,但它至少是多线程的。

from SocketServer import ThreadingMixIn
from BaseHTTPServer import HTTPServer

class MultiThreadedHTTPServer(ThreadingMixIn, HTTPServer):
    pass