BaseHttpRequestHandler设置全局值

时间:2018-08-08 17:28:22

标签: python class load instance basehttprequesthandler

我在这里有一个小问题,在这里上课:

class Skynet(SkynetServer):
def __init__(self):
    self.SkynetStatus = False

    SkynetServer.__init__(self)


def skynet_server_start(self):
    if not self.skynet and self.server_status:
        self.skynet = True
        self.skynet_process = Process(target=self.skynet_start)
        self.skynet_process.start()
    else: print("Start Server first!")

def skynet_server_stop(self):
    self.skynet = False
    self.skynet_stop()

呼吁:

class SkynetServer_RequestHandler(BaseHTTPRequestHandler)
def do_GET(self):
    self._set_headers()
    if self.path == "/":
        self.wfile.write("<html><body><h1>hi!</h1></body></html>".encode("utf-8"))
    if self.path == "chunk":
        print(self.SkynetStatus)
def log_message(self, format, *args):
    return

class SkynetServer():
def __init__(self):
    self.httpd = None

def skynet_start(self):
    host = '192.168.178.31'
    port = 23575
    httpd = HTTPServer((host, port), SkynetServer_RequestHandler)
    httpd.serve_forever()

所以我的问题是:如何在requesthandler中使用Skyne实例的self.SkynetStatus值? 不知道如何加载...。 希望你们知道我的意思;)

1 个答案:

答案 0 :(得分:0)

我用另一种方式解决了这个问题=)