Skip to content

Commit

Permalink
allow assigning a port in DaphneProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammedSaleh2001 committed Feb 20, 2025
1 parent 630caed commit 8d87442
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions daphne/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -153,7 +153,7 @@ def run(self):

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,
Expand Down

0 comments on commit 8d87442

Please sign in to comment.