Daemonizing python's BaseHTTPServer

后端 未结 6 1883
南方客
南方客 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:25

    A simple solution that worked for me was to override the BaseHTTPRequestHandler method log_message(), so we prevent any kind of writing in stdout and avoid problems when demonizing.

    class CustomRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    
        def log_message(self, format, *args):
                pass
    
    ...
    rest of custom class code
    ...
    

提交回复
热议问题