当前位置: 首页>>代码示例>>Python>>正文


Python epollreactor.install函数代码示例

本文整理汇总了Python中twisted.internet.epollreactor.install函数的典型用法代码示例。如果您正苦于以下问题:Python install函数的具体用法?Python install怎么用?Python install使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了install函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: installCommonReactor

def installCommonReactor():
    try:
        from twisted.internet import kqreactor
        kqreactor.install()
        return
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        pass
    try:
        from twisted.internet import epollreactor
        epollreactor.install()
        return
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        pass
    try:
        from twisted.internet import pollreactor
        pollreactor.install()
        return
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        pass
开发者ID:ericflo,项目名称:ircitude,代码行数:25,代码来源:irc_twisted.py

示例2: set_reactor

    def set_reactor():
        import platform

        REACTORNAME = DEFAULT_REACTORS.get(platform.system(), "select")
        # get the reactor in here
        if REACTORNAME == "kqueue":
            from twisted.internet import kqreactor

            kqreactor.install()
        elif REACTORNAME == "epoll":
            from twisted.internet import epollreactor

            epollreactor.install()
        elif REACTORNAME == "poll":
            from twisted.internet import pollreactor

            pollreactor.install()
        else:  # select is the default
            from twisted.internet import selectreactor

            selectreactor.install()

        from twisted.internet import reactor

        set_reactor = lambda: reactor
        return reactor
开发者ID:ziegeer,项目名称:droned,代码行数:26,代码来源:__main__.py

示例3: setup

def setup(setup_event=None):
    try:
        from twisted.internet import epollreactor
        epollreactor.install()
    except ImportError:
        print "Failed to install epoll reactor, default reactor will be used instead."
    
    try:
        import settings
    except ImportError:
        print "***** Is configs.py missing? Maybe you want to copy and customize config_default.py?"

    from twisted.application import service
    application = service.Application("stratum-server")

    # Setting up logging
    from twisted.python.log import ILogObserver, FileLogObserver
    from twisted.python.logfile import DailyLogFile

    #logfile = DailyLogFile(settings.LOGFILE, settings.LOGDIR)
    #application.setComponent(ILogObserver, FileLogObserver(logfile).emit)

    if settings.ENABLE_EXAMPLE_SERVICE:
        import stratum.example_service
    
    if setup_event == None:
        setup_finalize(None, application)
    else:
        setup_event.addCallback(setup_finalize, application)
        
    return application
开发者ID:Lietmotiv,项目名称:stratum,代码行数:31,代码来源:server.py

示例4: run_twisted

def run_twisted(host, port, barrier, profile):

    if 'bsd' in sys.platform or sys.platform.startswith('darwin'):
        from twisted.internet import kqreactor
        kqreactor.install()
    elif sys.platform in ['win32']:
        from twisted.internet.iocpreactor import reactor as iocpreactor
        iocpreactor.install()
    elif sys.platform.startswith('linux'):
        from twisted.internet import epollreactor
        epollreactor.install()
    else:
        from twisted.internet import default as defaultreactor
        defaultreactor.install()

    from twisted.web.server import Site
    from twisted.web.resource import Resource
    from twisted.internet import reactor

    class TestResource(Resource):

        def __init__(self, name):
            super().__init__()
            self.name = name
            self.isLeaf = name is not None

        def render_GET(self, request):
            txt = 'Hello, ' + self.name
            request.setHeader(b'Content-Type', b'text/plain; charset=utf-8')
            return txt.encode('utf8')

        def getChild(self, name, request):
            return TestResource(name=name.decode('utf-8'))

    class PrepareResource(Resource):

        isLeaf = True

        def render_GET(self, request):
            gc.collect()
            return b'OK'

    class StopResource(Resource):

        isLeaf = True

        def render_GET(self, request):
            reactor.callLater(0.1, reactor.stop)
            return b'OK'

    root = Resource()
    root.putChild(b'test', TestResource(None))
    root.putChild(b'prepare', PrepareResource())
    root.putChild(b'stop', StopResource())
    site = Site(root)
    reactor.listenTCP(port, site, interface=host)
    barrier.wait()

    reactor.run()
开发者ID:cr0hn,项目名称:aiohttp,代码行数:59,代码来源:async.py

示例5: main

def main():
    print 'logserver has started.'
    logger = logging.getLogger('log_server')
    logger.info('logserver has started.')
     
    from twisted.internet import epollreactor
    epollreactor.install()
    reactor = twisted.internet.reactor
    reactor.listenTCP(settings.PORT, ReceiveFactory())
    reactor.run()
开发者ID:yindashan,项目名称:log_server,代码行数:10,代码来源:socket_logserver.py

示例6: install_optimal_reactor

def install_optimal_reactor():
   """
   Try to install the optimal Twisted reactor for platform.
   """
   import sys

   if 'bsd' in sys.platform or sys.platform.startswith('darwin'):
      try:
         v = sys.version_info
         if v[0] == 1 or (v[0] == 2 and v[1] < 6) or (v[0] == 2 and v[1] == 6 and v[2] < 5):
            raise Exception("Python version too old (%s)" % sys.version)
         from twisted.internet import kqreactor
         kqreactor.install()
      except Exception as e:
         print("""
   WARNING: Running on BSD or Darwin, but cannot use kqueue Twisted reactor.

    => %s

   To use the kqueue Twisted reactor, you will need:

     1. Python >= 2.6.5 or PyPy > 1.8
     2. Twisted > 12.0

   Note the use of >= and >.

   Will let Twisted choose a default reactor (potential performance degradation).
   """ % str(e))
         pass

   if sys.platform in ['win32']:
      try:
         from twisted.application.reactors import installReactor
         installReactor("iocp")
      except Exception as e:
         print("""
   WARNING: Running on Windows, but cannot use IOCP Twisted reactor.

    => %s

   Will let Twisted choose a default reactor (potential performance degradation).
   """ % str(e))

   if sys.platform.startswith('linux'):
      try:
         from twisted.internet import epollreactor
         epollreactor.install()
      except Exception as e:
         print("""
   WARNING: Running on Linux, but cannot use Epoll Twisted reactor.

    => %s

   Will let Twisted choose a default reactor (potential performance degradation).
   """ % str(e))
开发者ID:luxorv,项目名称:Chat-GBH,代码行数:55,代码来源:choosereactor.py

示例7: run

def run():
    if platform.system() != "Windows":
        if not sys.modules.has_key('twisted.internet.reactor'):
            print "installing epoll reactor"
            from twisted.internet import epollreactor
            epollreactor.install()
        else:
            print "reactor already installed"
    from twisted.internet import reactor
    application = makeApplication(sys.argv)
    app.startApplication(application, None)
    reactor.run()
开发者ID:arem,项目名称:poker-network,代码行数:12,代码来源:pokerserver.py

示例8: run

def run():
    twisted_log.startLogging(sys.stdout)
    if platform.system() != "Windows":
        if 'twisted.internet.reactor' not in sys.modules:
            log.debug("installing epoll reactor")
            from twisted.internet import epollreactor
            epollreactor.install()
        else:
            log.debug("reactor already installed")
    from twisted.internet import reactor
    application = makeApplication(sys.argv)
    app.startApplication(application, None)
    reactor.run()
开发者ID:Usr-X,项目名称:poker-network,代码行数:13,代码来源:pokerserver.py

示例9: main

def main():
    
    parser = OptionParser()
    parser.add_option('-l', '--loglevel', default='info', dest='logLevel', help='This sets the logging level you have these options: debug, info, warning, error, critical \t\tThe standard value is info')
    parser.add_option('-p', '--port', default=443, type='int', dest='port', help='This option lets you use a custom port instead of 443 (use a port > 1024 to run as non root user)')
    parser.add_option('--logfile', default=None, dest='logfile', help='Log to a file instead of stdout.')
    parser.add_option('-m', '--maxConnections', default=None, type='int', dest='maxConnections', help='You can limit the number of maximum simultaneous connections with that switch')
    parser.add_option('-f', '--forcebuild', default=None, dest='customHostname', help='This option will force rebuild the certificate using the custom hostname and exit.')
    parser.add_option('-n', '--noSSL', action="store_true", default=False, dest='sslDisabled', help='You can switch off SSL with this switch.')
    (options, _) = parser.parse_args()
    
    x = logging.getLogger()
    x.setLevel(log_levels[options.logLevel])
    
    if options.logfile != None:
        h = logging.FileHandler(options.logfile)
    else:
        h = logging.StreamHandler()
    
    f = logging.Formatter(u"%(levelname)s %(message)s")
    h.setFormatter(f)
    x.addHandler(h)
    
    if not options.sslDisabled:
        create_self_signed_cert(options.customHostname)
        if options.customHostname != None:
            return
    
    try: 
        from twisted.internet import epollreactor
        epollreactor.install()
    except ImportError:
        x.debug("System does not support epoll")
        x.debug("-> Will use simple poll")
        try:
            from twisted.internet import pollreactor
            pollreactor.install()
        except ImportError:
            x.debug("System does not support poll")
            x.debug("-> Will use default select interface")
    from twisted.internet import reactor

    
    x.info("Starting server on port {0}".format(options.port))
    if options.sslDisabled:
        x.warning("Starting, as requested, without SSL, connections are not secured and can be altered and eavesdropped on from client to server")
        reactor.listenTCP(options.port, SiriFactory(options.maxConnections))
    else:
        reactor.listenSSL(options.port, SiriFactory(options.maxConnections), ssl.DefaultOpenSSLContextFactory(SERVER_KEY_FILE, SERVER_CERT_FILE))
    reactor.run()
    x.info("Server shutdown complete")
开发者ID:linusyang,项目名称:SiriServerCore,代码行数:51,代码来源:SiriServer.py

示例10: main

def main():
    
    parser = OptionParser()
    parser.add_option('-l', '--loglevel', default='info', dest='logLevel', help='This sets the logging level you have these options: debug, info, warning, error, critical \t\tThe standard value is info')
    parser.add_option('-p', '--port', default=443, type='int', dest='port', help='This options lets you use a custom port instead of 443 (use a port > 1024 to run as non root user)')
    parser.add_option('--logfile', default=None, dest='logfile', help='Log to a file instead of stdout.')
    parser.add_option('-m', '--maxConnections', default=None, type='int', dest='maxConnections', help='You can limit the number of maximum simultaneous connections with that switch')
    parser.add_option('-f', '--forcelanguage', action='store_true', default=False, dest='forcelanguage', help='Force the server use language by region of device and ignore the Siri Settings language. Usefull with anyvoice cydia package. Adds functionallity for unsupported languages')
    (options, _) = parser.parse_args()
    
    x = logging.getLogger()
    x.setLevel(log_levels[options.logLevel])
    
    if options.logfile != None:
        h = logging.FileHandler(options.logfile)
    else:
        h = logging.StreamHandler()
    
    f = logging.Formatter(u"%(levelname)s %(message)s")
    h.setFormatter(f)
    x.addHandler(h)
    
    if options.forcelanguage != False:
        config.forcelanguage=True
        x.info("Forcing languages to device region and ignoring Siri Languge settings")
    else:
        config.forcelanguage=False
    
    create_self_signed_cert()
    
    try: 
        from twisted.internet import epollreactor
        epollreactor.install()
    except ImportError:
        x.debug("System does not support epoll")
        x.debug("-> Will use simple poll")
        try:
            from twisted.internet import pollreactor
            pollreactor.install()
        except ImportError:
            x.debug("System does not support poll")
            x.debug("-> Will use default select interface")
    from twisted.internet import reactor

    
    x.info("Starting server on port {0}".format(options.port))
    reactor.listenSSL(options.port, SiriFactory(options.maxConnections), ssl.DefaultOpenSSLContextFactory(SERVER_KEY_FILE, SERVER_CERT_FILE))
    reactor.run()
    x.info("Server shutdown complete")
开发者ID:CryZeo,项目名称:TurkceSiriSunucu,代码行数:49,代码来源:SiriServer.py

示例11: installReactor

def installReactor():
    # Tries to install epoll first, then poll, and if neither are
    # available, the default select reactor will install when
    # twisted.internet.reactor is imported.
    try:
        from select import epoll
        from twisted.internet import epollreactor
        epollreactor.install()
    except ImportError:
        try:
            from select import poll
            from twisted.internet import pollreactor
            pollreactor.install()
        except ImportError:
            pass
开发者ID:zenoss,项目名称:zenoss-prodbin,代码行数:15,代码来源:__init__.py

示例12: __install_named_reactor

def __install_named_reactor(reactor_name, reactor_specific=None):
    """Setup a proper Twisted reactor, given its name.

    @precondition: reactor_name in SUPPORTED_REACTOR_NAMES

    @param reactor_specific: some arguments which are specific
        for a particular reactor (a bit hacky, yes).
        If C{reactor_name} == 'qt4': contains particular C{QCoreApplication}
            subclass to be used for primary application creation.
            May be C{None}.

    @raises ImportError: if the reactor cannot be installed.
    @raises NotImplementedError: if such reactor name is unsupported.
    """
    logger.debug('Attempting to install %s reactor...', reactor_name)

    if reactor_name == 'epoll':
        from twisted.internet import epollreactor
        epollreactor.install()

    elif reactor_name == 'kqueue':
        from txkqr import kqreactor_ex
        kqreactor_ex.install()

    elif reactor_name == 'qt4':
        qapp_class = reactor_specific
        if qapp_class is not None:
            app = qapp_class(sys.argv)

        from contrib.qt4reactor import qt4reactor
        qt4reactor.install()

    elif reactor_name == 'win32':
        from twisted.internet import win32eventreactor
        win32eventreactor.install()

    elif reactor_name == 'zmq':
        from zmqr import zmqreactor
        zmqreactor.install()

    else:
        logger.debug('Cannot install %s reactor, using default', reactor_name)
        raise NotImplementedError('Unsupported reactor {!r}'
                                      .format(reactor_name))

    logger.debug('Installed %s reactor', reactor_name)
开发者ID:shvar,项目名称:redfs,代码行数:46,代码来源:system.py

示例13: main

def main():
    
    parser = OptionParser()
    parser.add_option('-l', '--loglevel', default='info', dest='logLevel', help='This sets the logging level you have these options: debug, info, warning, error, critical \t\tThe standard value is info')
    parser.add_option('-p', '--port', default=4443, type='int', dest='port', help='This options lets you use a custom port instead of 443 (use a port > 1024 to run as non root user)')
    parser.add_option('--logfile', default=None, dest='logfile', help='Log to a file instead of stdout.')
    (options, _) = parser.parse_args()
    
    x = logging.getLogger()
    x.setLevel(log_levels[options.logLevel])
    
    if options.logfile != None:
        h = logging.FileHandler(options.logfile)
    else:
        h = logging.StreamHandler()
    
    f = logging.Formatter(u"%(levelname)s %(message)s")
    h.setFormatter(f)
    x.addHandler(h)
    
    create_self_signed_cert()
    
    try: 
        from twisted.internet import epollreactor
        epollreactor.install()
    except ImportError:
        x.debug("System does not support epoll")
        x.debug("-> Will use simple poll")
        try:
            from twisted.internet import pollreactor
            pollreactor.install()
        except ImportError:
            x.debug("System does not support poll")
            x.debug("-> Will use default select interface")
    from twisted.internet import reactor

    
    x.info("Starting server on port {0}".format(options.port))
    reactor.listenSSL(options.port, SiriFactory(), ssl.DefaultOpenSSLContextFactory(SERVER_KEY_FILE, SERVER_CERT_FILE))
    reactor.run()
    x.info("Server shutdown complete")
开发者ID:gfarrell,项目名称:SiriServerCore,代码行数:41,代码来源:SiriServer.py

示例14: set_reactor

    def set_reactor(self):
        """sets the reactor up"""
        #get the reactor in here
        if self.REACTORNAME == 'kqueue':
            from twisted.internet import kqreactor
            kqreactor.install()
        elif self.REACTORNAME == 'epoll':
            from twisted.internet import epollreactor
            epollreactor.install()
        elif self.REACTORNAME == 'poll':
            from twisted.internet import pollreactor
            pollreactor.install()
        else: #select is the default
            from twisted.internet import selectreactor
            selectreactor.install()

        from twisted.internet import reactor
        self.reactor = reactor
        #shouldn't have to, but sys.exit is scary
        self.reactor.callWhenRunning(self._protect)
        #prevent this from being called ever again
        self.set_reactor = lambda: None
开发者ID:mleinart,项目名称:droned,代码行数:22,代码来源:droned-daemon.py

示例15: singleton

import sys
import thread

from monocle import launch

# prefer fast reactors
# FIXME: this should optionally refuse to use slow ones
if not "twisted.internet.reactor" in sys.modules:
    try:
        from twisted.internet import epollreactor
        epollreactor.install()
    except:
        try:
            from twisted.internet import kqreactor
            kqreactor.install()
        except:
            try:
                from twisted.internet import pollreactor
                pollreactor.install()
            except:
                pass

from twisted.internet import reactor
try:
    from twisted.internet.error import ReactorNotRunning
except ImportError:
    ReactorNotRunning = RuntimeError


# thanks to Peter Norvig
def singleton(object, message="singleton class already instantiated",
开发者ID:ChrisWren,项目名称:monocle,代码行数:31,代码来源:eventloop.py


注:本文中的twisted.internet.epollreactor.install函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。