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

Commit

Permalink
Merge pull request #272 from bjoernricks/use-daemon-mode-for-python-3.7
Browse files Browse the repository at this point in the history
Use daemon mode for python 3.7
  • Loading branch information
jjnicola committed May 14, 2020
2 parents e37a45c + 8b032f5 commit 86746f5
Showing 1 changed file with 13 additions and 4 deletions.
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

0 comments on commit 86746f5

Please sign in to comment.