mirror of
https://github.com/django/daphne.git
synced 2025-07-29 16:39:46 +03:00
Resolve asyncio + multiprocessing problem
This commit is contained in:
parent
d3630e0925
commit
13abad2f89
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
|
.idea/
|
||||||
*.egg-info
|
*.egg-info
|
||||||
*.pyc
|
*.pyc
|
||||||
__pycache__
|
__pycache__
|
||||||
|
|
|
@ -122,6 +122,16 @@ class DaphneProcess(multiprocessing.Process):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
|
# Renew the asyncio event loop without anyone knowing.
|
||||||
|
# This is necessary because asyncio behaves badly with multiprocessing.
|
||||||
|
from twisted.internet import asyncioreactor
|
||||||
|
import sys
|
||||||
|
current_reactor = sys.modules.get("twisted.internet.reactor")
|
||||||
|
if isinstance(current_reactor, asyncioreactor.AsyncioSelectorReactor):
|
||||||
|
import asyncio
|
||||||
|
current_reactor._asyncioEventloop.close()
|
||||||
|
asyncio.set_event_loop(asyncio.new_event_loop())
|
||||||
|
current_reactor._asyncioEventloop = asyncio.get_event_loop()
|
||||||
# Create the server class
|
# Create the server class
|
||||||
endpoints = build_endpoint_description_strings(host=self.host, port=0)
|
endpoints = build_endpoint_description_strings(host=self.host, port=0)
|
||||||
self.server = Server(
|
self.server = Server(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user