Skip to content

Commit

Permalink
Add Python's socketserver.ThreadingMixin to the threaded test HTTP se…
Browse files Browse the repository at this point in the history
…rver, and enable the 'daemon_threads' setting

Ref: https://docs.python.org/3/library/socketserver.html#socketserver.ThreadingMixIn
  • Loading branch information
jayaddison committed Apr 18, 2023
1 parent a33fc9e commit cbc43ac
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import contextlib
import http.server
import pathlib
import socketserver
import threading
from ssl import PROTOCOL_TLS_SERVER, SSLContext

Expand All @@ -16,10 +17,14 @@
LOCK_PATH = str(TESTS_ROOT / 'test-server.lock')


class ThreadedHttpServer(socketserver.ThreadingMixIn, http.server.HTTPServer):
daemon_threads = True


class HttpServerThread(threading.Thread):
def __init__(self, handler, *args, **kwargs):
super().__init__(*args, **kwargs)
self.server = http.server.HTTPServer(("localhost", 7777), handler)
self.server = ThreadedHttpServer(("localhost", 7777), handler)

def run(self):
self.server.serve_forever(poll_interval=0.001)
Expand Down

0 comments on commit cbc43ac

Please sign in to comment.