]> code.delx.au - pymsnt/commitdiff
Cleaned up reactor autodetection code
authorJames Bunton <jamesbunton@fastmail.fm>
Sun, 29 Jul 2007 05:45:11 +0000 (15:45 +1000)
committerJames Bunton <jamesbunton@fastmail.fm>
Sun, 29 Jul 2007 05:45:11 +0000 (15:45 +1000)
src/main.py

index b31aa8e895e129f12c3ba2011e38eb3bed2f9a23..6b1587a0562a46791ecc2aac36fadce900b18776 100644 (file)
@@ -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