mirror of
https://github.com/django/daphne.git
synced 2024-11-11 02:26:35 +03:00
Better Twisted reactor detection
This commit is contained in:
parent
0f8f731b2c
commit
826a8ce0de
|
@ -2,15 +2,19 @@
|
||||||
import sys # isort:skip
|
import sys # isort:skip
|
||||||
import warnings # isort:skip
|
import warnings # isort:skip
|
||||||
from twisted.internet import asyncioreactor # isort:skip
|
from twisted.internet import asyncioreactor # isort:skip
|
||||||
if "twisted.internet.reactor" in sys.modules:
|
current_reactor = sys.modules.get("twisted.internet.reactor", None)
|
||||||
warnings.warn(
|
if current_reactor is not None:
|
||||||
"Something has already installed a Twisted reactor. Attempting to uninstall it; " +
|
if not isinstance(current_reactor, asyncioreactor.AsyncioSelectorReactor):
|
||||||
"you can fix this warning by importing daphne.server early in your codebase or " +
|
warnings.warn(
|
||||||
"finding the package that imports Twisted and importing it later on.",
|
"Something has already installed a non-asyncio Twisted reactor. Attempting to uninstall it; " +
|
||||||
UserWarning,
|
"you can fix this warning by importing daphne.server early in your codebase or " +
|
||||||
)
|
"finding the package that imports Twisted and importing it later on.",
|
||||||
del sys.modules["twisted.internet.reactor"]
|
UserWarning,
|
||||||
asyncioreactor.install()
|
)
|
||||||
|
del sys.modules["twisted.internet.reactor"]
|
||||||
|
asyncioreactor.install()
|
||||||
|
else:
|
||||||
|
asyncioreactor.install()
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
Loading…
Reference in New Issue
Block a user