allow assigning a port in DaphneProcess

This commit is contained in:
Mohammed 2025-02-20 17:25:59 +00:00
parent 630caed915
commit 8d87442ed1

View File

@ -126,14 +126,14 @@ class DaphneProcess(multiprocessing.Process):
port it ends up listening on back to the parent process.
"""
def __init__(self, host, get_application, kwargs=None, setup=None, teardown=None):
def __init__(self, host, get_application, kwargs=None, setup=None, teardown=None, port=None):
super().__init__()
self.host = host
self.get_application = get_application
self.kwargs = kwargs or {}
self.setup = setup
self.teardown = teardown
self.port = multiprocessing.Value("i")
self.port = multiprocessing.Value("i", port if port is not None else 0)
self.ready = multiprocessing.Event()
self.errors = multiprocessing.Queue()
@ -153,7 +153,7 @@ class DaphneProcess(multiprocessing.Process):
try:
# Create the server class
endpoints = build_endpoint_description_strings(host=self.host, port=0)
endpoints = build_endpoint_description_strings(host=self.host, port=self.port.value)
self.server = Server(
application=application,
endpoints=endpoints,