Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中用于处理get请求的多线程HTTP服务器_Python_Python 3.x_Multithreading_Python Multithreading_Simplehttpserver - Fatal编程技术网

python中用于处理get请求的多线程HTTP服务器

python中用于处理get请求的多线程HTTP服务器,python,python-3.x,multithreading,python-multithreading,simplehttpserver,Python,Python 3.x,Multithreading,Python Multithreading,Simplehttpserver,我需要在Python3中创建一个多线程web服务器,其中每个请求获得一个新线程。我遵循了博客中的一个基本示例。但是,服务器总是阻塞,因为在1线程中调用的睡眠会阻塞其他线程。有人能帮我吗 这是我的密码 import time from http.server import HTTPServer, BaseHTTPRequestHandler from socketserver import ThreadingMixIn import threading class Handler(BaseHT

我需要在Python3中创建一个多线程web服务器,其中每个请求获得一个新线程。我遵循了博客中的一个基本示例。但是,服务器总是阻塞,因为在1线程中调用的睡眠会阻塞其他线程。有人能帮我吗

这是我的密码

import time
from http.server import HTTPServer, BaseHTTPRequestHandler
from socketserver import ThreadingMixIn
import threading


class Handler(BaseHTTPRequestHandler):

    def do_GET(self):
        self.send_response(200)
        self.end_headers()
        print('start-->')
        time.sleep(5)
        print('end-->')
        self.wfile.write("Test".encode())


class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
    pass


def run():
    server = ThreadingSimpleServer(('0.0.0.0', 1234), Handler)
    server.serve_forever()


if __name__ == '__main__':
    run()
我的问题是,如果我向服务器发送2个请求,那么第二个请求只有在第一个请求完成后才开始执行。我需要睡眠在它自己的线程上,而不影响其他线程。如果有任何帮助,我将不胜感激