Possible fix for server issues. Instead of using a timer, use the socket timeout, and ensure that we stop server before spawning a new one.
This commit is contained in:
@@ -36,7 +36,6 @@ class Crest():
|
||||
self.httpd = None
|
||||
self.state = None
|
||||
self.ssoTimer = None
|
||||
self.httpdTimer = None
|
||||
|
||||
# Base EVE connection that is copied to all characters
|
||||
self.eve = service.pycrest.EVE(
|
||||
@@ -107,16 +106,15 @@ class Crest():
|
||||
def stopServer(self):
|
||||
logging.debug("Stopping Server")
|
||||
self.httpd.stop()
|
||||
self.httpd = None
|
||||
|
||||
def startServer(self):
|
||||
logging.debug("Starting server")
|
||||
if self.httpd:
|
||||
self.stopServer()
|
||||
self.httpd = service.StoppableHTTPServer(('', 6461), service.AuthHandler)
|
||||
thread.start_new_thread(self.httpd.serve, ())
|
||||
|
||||
# keep server going for only 60 seconds
|
||||
self.httpdTimer = threading.Timer(60, self.stopServer)
|
||||
self.httpdTimer.start()
|
||||
|
||||
self.state = str(uuid.uuid4())
|
||||
return self.eve.auth_uri(scopes=self.scopes, state=self.state)
|
||||
|
||||
@@ -169,3 +167,4 @@ class Crest():
|
||||
|
||||
wx.CallAfter(pub.sendMessage, 'login_success', type=1)
|
||||
|
||||
self.stopServer()
|
||||
|
||||
@@ -58,7 +58,8 @@ class StoppableHTTPServer(BaseHTTPServer.HTTPServer):
|
||||
|
||||
def server_bind(self):
|
||||
BaseHTTPServer.HTTPServer.server_bind(self)
|
||||
self.socket.settimeout(1)
|
||||
# Allow listeing for 60 seconds
|
||||
self.socket.settimeout(60)
|
||||
self.run = True
|
||||
|
||||
def get_request(self):
|
||||
@@ -71,8 +72,13 @@ class StoppableHTTPServer(BaseHTTPServer.HTTPServer):
|
||||
pass
|
||||
|
||||
def stop(self):
|
||||
self.socket.close()
|
||||
self.run = False
|
||||
|
||||
def handle_timeout(self):
|
||||
logger.debug("Server timed out waiting for connection")
|
||||
self.stop()
|
||||
|
||||
def serve(self):
|
||||
while self.run:
|
||||
try:
|
||||
@@ -86,3 +92,4 @@ if __name__ == "__main__":
|
||||
thread.start_new_thread(httpd.serve, ())
|
||||
raw_input("Press <RETURN> to stop server\n")
|
||||
httpd.stop()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user