MCPcopy Create free account
hub / github.com/comaps/comaps / InternalServer

Class InternalServer

tools/python/test_server/server/testserver.py:59–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57
58
59class InternalServer(HTTPServer):
60
61 def kill_me(self):
62 self.shutdown()
63 logging.info(f"The server's life has come to an end, pid: {os.getpid()}")
64
65
66 def reset_selfdestruct_timer(self):
67 if self.self_destruct_timer:
68 self.self_destruct_timer.cancel()
69
70 self.self_destruct_timer = Timer(LIFESPAN, self.kill_me)
71 self.self_destruct_timer.start()
72
73
74 def __init__(self, server_address, RequestHandlerClass,
75 bind_and_activate=True):
76
77 HTTPServer.__init__(self, server_address, RequestHandlerClass,
78 bind_and_activate=bind_and_activate)
79
80 self.self_destruct_timer = None
81 self.clients = 1
82 self.reset_selfdestruct_timer()
83
84
85 def suicide(self):
86 self.clients -= 1
87 if self.clients == 0:
88 if self.self_destruct_timer is not None:
89 self.self_destruct_timer.cancel()
90
91 quick_and_painless_timer = Timer(0.1, self.kill_me)
92 quick_and_painless_timer.start()
93
94
95class TestServer:

Callers 1

init_serverMethod · 0.85

Calls

no outgoing calls

Tested by 1

init_serverMethod · 0.68