MCPcopy Index your code
hub / github.com/pyfa-org/Pyfa / StoppableHTTPServer

Class StoppableHTTPServer

service/server.py:62–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60
61# http://code.activestate.com/recipes/425210-simple-stoppable-server-using-socket-timeout/
62class StoppableHTTPServer(socketserver.TCPServer):
63 def server_bind(self):
64 # Can't use HTTPServer due to reliance on socket.getfqdn() which seems to be bugged.
65 # See https://github.com/pyfa-org/Pyfa/issues/1560#issuecomment-390095101
66 socketserver.TCPServer.server_bind(self)
67 host, port = self.server_address[:2]
68 self.server_name = host
69 self.server_port = port
70
71 # self.settings = CRESTSettings.getInstance()
72
73 self.socket.settimeout(1)
74 self.run = True
75
76 def get_request(self):
77 while self.run:
78 try:
79 sock, addr = self.socket.accept()
80 sock.settimeout(None)
81 return sock, addr
82 except socket.timeout:
83 pyfalog.warning("Server timed out waiting for connection")
84 pass
85
86 def stop(self):
87 pyfalog.warning("Setting pyfa server to stop.")
88 self.run = False
89
90 def serve(self, callback=None):
91 self.callback = callback
92 while self.run:
93 try:
94 self.handle_request()
95 except TypeError:
96 pyfalog.debug("Caught exception in serve")
97 pass
98
99 self.server_close()
100
101
102if __name__ == "__main__":

Callers 2

startServerMethod · 0.90
server.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected