|
1 |
| -import multiprocessing |
| 1 | +from functools import partial |
2 | 2 |
|
3 | 3 | from daphne.testing import DaphneProcess
|
4 | 4 | from django.contrib.staticfiles.handlers import ASGIStaticFilesHandler
|
|
9 | 9 |
|
10 | 10 | from channels.routing import get_default_application
|
11 | 11 |
|
12 |
| -# Enforce multiprocessing start method for macOS. |
13 |
| -multiprocessing.set_start_method("fork") |
| 12 | + |
| 13 | +def make_application(*, static_wrapper): |
| 14 | + # Module-level function for pickle-ability |
| 15 | + application = get_default_application() |
| 16 | + if static_wrapper is not None: |
| 17 | + application = static_wrapper(application) |
| 18 | + return application |
14 | 19 |
|
15 | 20 |
|
16 | 21 | class ChannelsLiveServerTestCase(TransactionTestCase):
|
@@ -48,12 +53,11 @@ def _pre_setup(self):
|
48 | 53 | )
|
49 | 54 | self._live_server_modified_settings.enable()
|
50 | 55 |
|
51 |
| - if self.serve_static: |
52 |
| - application = self.static_wrapper(get_default_application()) |
53 |
| - else: |
54 |
| - application = get_default_application() |
55 |
| - |
56 |
| - self._server_process = self.ProtocolServerProcess(self.host, application) |
| 56 | + get_application = partial( |
| 57 | + make_application, |
| 58 | + static_wrapper=self.static_wrapper if self.serve_static else None, |
| 59 | + ) |
| 60 | + self._server_process = self.ProtocolServerProcess(self.host, get_application) |
57 | 61 | self._server_process.start()
|
58 | 62 | self._server_process.ready.wait()
|
59 | 63 | self._port = self._server_process.port.value
|
|
0 commit comments