diff --git a/daphne/server.py b/daphne/server.py index 7cdd61e..8390527 100755 --- a/daphne/server.py +++ b/daphne/server.py @@ -1,6 +1,15 @@ # This has to be done first as Twisted is import-order-sensitive with reactors +import sys # isort:skip +import warnings # isort:skip from twisted.internet import asyncioreactor # isort:skip -asyncioreactor.install() # isort:skip +if "twisted.internet.reactor" in sys.modules: + warnings.warn( + "Something has already installed a Twisted reactor. Attempting to uninstall it; ", + "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"] +asyncioreactor.install() import asyncio import logging