Try to uninstall previous reactors if they're found

This commit is contained in:
Andrew Godwin 2018-02-03 22:57:15 -08:00
parent 3b5721c699
commit 7949b244b8

View File

@ -1,6 +1,15 @@
# This has to be done first as Twisted is import-order-sensitive with reactors # 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 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 asyncio
import logging import logging