From 7949b244b887d2f19a5e1f17e6b0f206822dec53 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sat, 3 Feb 2018 22:57:15 -0800 Subject: [PATCH] Try to uninstall previous reactors if they're found --- daphne/server.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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