diff --git a/ospd/server.py b/ospd/server.py index a136e77a..c78a3477 100644 --- a/ospd/server.py +++ b/ospd/server.py @@ -158,6 +158,17 @@ def _start_threading_server(self): class SocketServerMixin: + # Use daemon mode to circrumvent a memory leak + # (reported at https://bugs.python.org/issue37193). + # + # Daemonic threads are killed immediately by the python interpreter without + # waiting for until they are finished. + # + # Maybe block_on_close = True could work too. + # In that case the interpreter waits for the threads to finish but doesn't + # track them in the _threads list. + daemon_threads = True + def __init__(self, server: BaseServer, address: Union[str, InetAddress]): self.server = server super().__init__(address, RequestHandler, bind_and_activate=True) @@ -167,15 +178,13 @@ def handle_request(self, request, client_address): class ThreadedUnixSocketServer( - SocketServerMixin, - socketserver.ThreadingMixIn, - socketserver.UnixStreamServer, + SocketServerMixin, socketserver.ThreadingUnixStreamServer, ): pass class ThreadedTlsSocketServer( - SocketServerMixin, socketserver.ThreadingMixIn, socketserver.TCPServer + SocketServerMixin, socketserver.ThreadingTCPServer, ): pass