mirror of
https://github.com/django/daphne.git
synced 2024-11-24 00:43:43 +03:00
Avoid Twisted using the default event loop
When switching threads, e.g. when run via Django auto-reloader, the default run loop causes issues detecting async contexts. Fixes https://github.com/django/channels/issues/1374
This commit is contained in:
parent
eb582d1d43
commit
27f760a814
|
@ -1,8 +1,10 @@
|
|||
# This has to be done first as Twisted is import-order-sensitive with reactors
|
||||
import asyncio # isort:skip
|
||||
import sys # isort:skip
|
||||
import warnings # isort:skip
|
||||
from twisted.internet import asyncioreactor # isort:skip
|
||||
|
||||
twisted_loop = asyncio.new_event_loop()
|
||||
current_reactor = sys.modules.get("twisted.internet.reactor", None)
|
||||
if current_reactor is not None:
|
||||
if not isinstance(current_reactor, asyncioreactor.AsyncioSelectorReactor):
|
||||
|
@ -13,11 +15,10 @@ if current_reactor is not None:
|
|||
UserWarning,
|
||||
)
|
||||
del sys.modules["twisted.internet.reactor"]
|
||||
asyncioreactor.install()
|
||||
asyncioreactor.install(twisted_loop)
|
||||
else:
|
||||
asyncioreactor.install()
|
||||
asyncioreactor.install(twisted_loop)
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import time
|
||||
import traceback
|
||||
|
|
Loading…
Reference in New Issue
Block a user