Daemonizing python's BaseHTTPServer

后端 未结 6 1892
南方客
南方客 2021-02-05 20:35

I am working on a daemon where I need to embed a HTTP server. I am attempting to do it with BaseHTTPServer, which when I run it in the foreground, it works fine, but when I tr

6条回答
  •  长发绾君心
    2021-02-05 21:18

    After a bit of googling I finally stumbled over this BaseHTTPServer documentation and after that I ended up with:

    from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
    from SocketServer import ThreadingMixIn
    
    class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
      """Handle requests in a separate thread."""
    
    server = ThreadedHTTPServer((config['HTTPServer']['listen'],config['HTTPServer']['port']), HTTPHandler)
    server.serve_forever()
    

    Which for the most part comes after I fork and ended up resolving my problem.

提交回复
热议问题