Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Use daemon mode for python 3.7 #272

Merged
merged 2 commits into from
May 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions ospd/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down