How to implement Timeout in BaseHTTPServer.BaseHTTPRequestHandler Python

前端 未结 7 1259
走了就别回头了
走了就别回头了 2021-01-19 01:46

In my python script, I am trying to run a web server:

server = BaseHTTPServer.HTTPServer((\'127.0.0.1\',8080), RequestHandler)

I have a req

相关标签:
7条回答
  • 2021-01-19 02:21

    I actually found that setting a value for self.timeout in def setup didn't work if I then called the superclass. It looks like the Handler's setup and init methods aren't called during creation of the HTTPServer instance. I used pydevd to confirm this.

    So, I took a backward step:

    httpd = BaseHTTPServer.HTTPServer(server_address, MyHttpHandler)
    httpd.timeout = 10
    

    Which works perfectly, and without overriding core code, or building your own derivative classes. It looks like you'd have to overwrite the HTTPServer code, rather than the Handler code, if you wanted to do it that way.

    0 讨论(0)
提交回复
热议问题