From f6093f68abff703c107db6dbc85fa2f3ee713fd3 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Sun, 29 Jul 2007 15:45:11 +1000 Subject: [PATCH] Cleaned up reactor autodetection code --- src/main.py | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/main.py b/src/main.py index b31aa8e..6b1587a 100644 --- a/src/main.py +++ b/src/main.py @@ -9,26 +9,19 @@ sys.stdout = codecs.lookup('utf-8')[-1](sys.stdout) # Find the best reactor selectWarning = "Unable to install any good reactors (kqueue, epoll, poll).\nWe fell back to using select. You may have scalability problems.\nThis reactor will not support more than 1024 connections at a time." -try: - from twisted.internet import epollreactor as bestreactor -except: - #try: - #from twisted.internet import kqreactor as bestreactor - #except: +reactors = [("epollreactor", True), ("pollreactor", True), ("selectreactor", False), ("default", False)] +for tryReactor, good in reactors: try: - from twisted.internet import pollreactor as bestreactor - except: - try: - from twisted.internet import selectreactor as bestreactor - print selectWarning - except: - try: - from twisted.internet import default as bestreactor - print selectWarning - except: - print "Unable to find a reactor. Please make sure you have Twisted properly installed.\nExiting..." - sys.exit(1) -bestreactor.install() + bestReactor = __import__("twisted.internet." + tryReactor) + if not good: + print >> sys.stderr, selectWarning + break + except ImportError: + pass +else: + print >> sys.stderr, "Unable to find a reactor. Please make sure you have Twisted properly installed.\nExiting..." + sys.exit(1) + import twistfix twistfix.main() @@ -90,7 +83,7 @@ if config.reactor: from twisted.internet import kqreactor kqreactor.install() elif len(config.reactor) > 0: - print "Unknown reactor: ", config.reactor, ". Using select(), reactor." + print >> sys.stderr, "Unknown reactor: ", config.reactor, ". Using best available reactor." from twisted.internet import reactor, task -- 2.39.2