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


Python kqreactor.install函数代码示例

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


在下文中一共展示了install函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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, 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
开发者ID:ajjoshi,项目名称:AutobahnPython,代码行数:29,代码来源:choosereactor.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: install_reactor

def install_reactor():
    # BSD and Mac OS X, kqueue
    try:
        from twisted.internet import kqreactor as event_reactor
    except:
        # Linux 2.6 and newer, epoll
        try:
            from twisted.internet import epollreactor as event_reactor
        except:
            # Linux pre-2.6, poll
            from twisted.internet import pollreactor as event_reactor
    event_reactor.install()
    from twisted.internet import reactor
    return reactor
开发者ID:mk-fg,项目名称:convergence,代码行数:14,代码来源:core.py

示例6: 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

示例7: 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

示例8: install_optimal_reactor

def install_optimal_reactor(require_optimal_reactor=True):
    """
    Try to install the optimal Twisted reactor for this platform:

    - Linux:   epoll
    - BSD/OSX: kqueue
    - Windows: iocp
    - Other:   select

    Notes:

    - This function exists, because the reactor types selected based on platform
      in `twisted.internet.default` are different from here.
    - The imports are inlined, because the Twisted code base is notorious for
      importing the reactor as a side-effect of merely importing. Hence we postpone
      all importing.

    See: http://twistedmatrix.com/documents/current/core/howto/choosing-reactor.html#reactor-functionality

    :param require_optimal_reactor: If ``True`` and the desired reactor could not be installed,
        raise ``ReactorAlreadyInstalledError``, else fallback to another reactor.
    :type require_optimal_reactor: bool

    :returns: The Twisted reactor in place (`twisted.internet.reactor`).
    """
    log = txaio.make_logger()

    # determine currently installed reactor, if any
    #
    current_reactor = current_reactor_klass()

    # depending on platform, install optimal reactor
    #
    if 'bsd' in sys.platform or sys.platform.startswith('darwin'):

        # *BSD and MacOSX
        #
        if current_reactor != 'KQueueReactor':
            if current_reactor is None:
                try:
                    from twisted.internet import kqreactor
                    kqreactor.install()
                except:
                    log.warn('Running on *BSD or MacOSX, but cannot install kqueue Twisted reactor: {tb}', tb=traceback.format_exc())
                else:
                    log.debug('Running on *BSD or MacOSX and optimal reactor (kqueue) was installed.')
            else:
                log.warn('Running on *BSD or MacOSX, but cannot install kqueue Twisted reactor, because another reactor ({klass}) is already installed.', klass=current_reactor)
                if require_optimal_reactor:
                    raise ReactorAlreadyInstalledError()
        else:
            log.debug('Running on *BSD or MacOSX and optimal reactor (kqueue) already installed.')

    elif sys.platform in ['win32']:

        # Windows
        #
        if current_reactor != 'IOCPReactor':
            if current_reactor is None:
                try:
                    from twisted.internet.iocpreactor import reactor as iocpreactor
                    iocpreactor.install()
                except:
                    log.warn('Running on Windows, but cannot install IOCP Twisted reactor: {tb}', tb=traceback.format_exc())
                else:
                    log.debug('Running on Windows and optimal reactor (ICOP) was installed.')
            else:
                log.warn('Running on Windows, but cannot install IOCP Twisted reactor, because another reactor ({klass}) is already installed.', klass=current_reactor)
                if require_optimal_reactor:
                    raise ReactorAlreadyInstalledError()
        else:
            log.debug('Running on Windows and optimal reactor (ICOP) already installed.')

    elif sys.platform.startswith('linux'):

        # Linux
        #
        if current_reactor != 'EPollReactor':
            if current_reactor is None:
                try:
                    from twisted.internet import epollreactor
                    epollreactor.install()
                except:
                    log.warn('Running on Linux, but cannot install Epoll Twisted reactor: {tb}', tb=traceback.format_exc())
                else:
                    log.debug('Running on Linux and optimal reactor (epoll) was installed.')
            else:
                log.warn('Running on Linux, but cannot install Epoll Twisted reactor, because another reactor ({klass}) is already installed.', klass=current_reactor)
                if require_optimal_reactor:
                    raise ReactorAlreadyInstalledError()
        else:
            log.debug('Running on Linux and optimal reactor (epoll) already installed.')

    else:

        # Other platform
        #
        if current_reactor != 'SelectReactor':
            if current_reactor is None:
                try:
#.........这里部分代码省略.........
开发者ID:crossbario,项目名称:autobahn-python,代码行数:101,代码来源:choosereactor.py

示例9: install_optimal_reactor

def install_optimal_reactor(verbose=False):
    """
    Try to install the optimal Twisted reactor for this platform.

    :param verbose: If ``True``, print what happens.
    :type verbose: bool
    """
    log = make_logger()

    import sys
    from twisted.python import reflect
    import txaio
    txaio.use_twisted()  # just to be sure...
    # XXX should I configure txaio.config.loop in here too, or just in
    # install_reactor()? (I am: see bottom of function)

    # determine currently installed reactor, if any
    ##
    if 'twisted.internet.reactor' in sys.modules:
        current_reactor = reflect.qual(sys.modules['twisted.internet.reactor'].__class__).split('.')[-1]
    else:
        current_reactor = None

    # depending on platform, install optimal reactor
    ##
    if 'bsd' in sys.platform or sys.platform.startswith('darwin'):

        # *BSD and MacOSX
        ##
        if current_reactor != 'KQueueReactor':
            try:
                from twisted.internet import kqreactor
                kqreactor.install()
            except:
                log.critical("Running on *BSD or MacOSX, but cannot install kqueue Twisted reactor")
                log.debug(traceback.format_exc())
            else:
                log.debug("Running on *BSD or MacOSX and optimal reactor (kqueue) was installed.")
        else:
            log.debug("Running on *BSD or MacOSX and optimal reactor (kqueue) already installed.")

    elif sys.platform in ['win32']:

        # Windows
        ##
        if current_reactor != 'IOCPReactor':
            try:
                from twisted.internet.iocpreactor import reactor as iocpreactor
                iocpreactor.install()
            except:
                log.critical("Running on Windows, but cannot install IOCP Twisted reactor")
                log.debug(traceback.format_exc())
            else:
                log.debug("Running on Windows and optimal reactor (ICOP) was installed.")
        else:
            log.debug("Running on Windows and optimal reactor (ICOP) already installed.")

    elif sys.platform.startswith('linux'):

        # Linux
        ##
        if current_reactor != 'EPollReactor':
            try:
                from twisted.internet import epollreactor
                epollreactor.install()
            except:
                log.critical("Running on Linux, but cannot install Epoll Twisted reactor")
                log.debug(traceback.format_exc())
            else:
                log.debug("Running on Linux and optimal reactor (epoll) was installed.")
        else:
            log.debug("Running on Linux and optimal reactor (epoll) already installed.")

    else:
        try:
            from twisted.internet import default as defaultreactor
            defaultreactor.install()
        except:
            log.critical("Could not install default Twisted reactor for this platform")
            log.debug(traceback.format_exc())

    from twisted.internet import reactor
    txaio.config.loop = reactor
开发者ID:honeyflyfish,项目名称:autobahn-python,代码行数:83,代码来源:choosereactor.py

示例10: install_optimal_reactor

def install_optimal_reactor(verbose=False):
    """
   Try to install the optimal Twisted reactor for platform.

   :param verbose: If ``True``, print what happens.
   :type verbose: bool
   """
    import sys
    from twisted.python import reflect
    from twisted.python import log

    ## determine currently installed reactor, if any
    ##
    if "twisted.internet.reactor" in sys.modules:
        current_reactor = reflect.qual(sys.modules["twisted.internet.reactor"].__class__).split(".")[-1]
    else:
        current_reactor = None

    ## depending on platform, install optimal reactor
    ##
    if "bsd" in sys.platform or sys.platform.startswith("darwin"):

        ## *BSD and MacOSX
        ##
        if current_reactor != "KQueueReactor":
            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 ({0}) to use kqueue reactor".format(sys.version))
                from twisted.internet import kqreactor

                kqreactor.install()
            except Exception as e:
                log.err(
                    "WARNING: Running on *BSD or MacOSX, but cannot install kqueue Twisted reactor ({0}).".format(e)
                )
            else:
                if verbose:
                    log.msg("Running on *BSD or MacOSX and optimal reactor (kqueue) was installed.")
        else:
            if verbose:
                log.msg("Running on *BSD or MacOSX and optimal reactor (kqueue) already installed.")

    elif sys.platform in ["win32"]:

        ## Windows
        ##
        if current_reactor != "IOCPReactor":
            try:
                from twisted.internet.iocpreactor import reactor as iocpreactor

                iocpreactor.install()
            except Exception as e:
                log.err("WARNING: Running on Windows, but cannot install IOCP Twisted reactor ({0}).".format(e))
            else:
                if verbose:
                    log.msg("Running on Windows and optimal reactor (ICOP) was installed.")
        else:
            if verbose:
                log.msg("Running on Windows and optimal reactor (ICOP) already installed.")

    elif sys.platform.startswith("linux"):

        ## Linux
        ##
        if current_reactor != "EPollReactor":
            try:
                from twisted.internet import epollreactor

                epollreactor.install()
            except Exception as e:
                log.err("WARNING: Running on Linux, but cannot install Epoll Twisted reactor ({0}).".format(e))
            else:
                if verbose:
                    log.msg("Running on Linux and optimal reactor (epoll) was installed.")
        else:
            if verbose:
                log.msg("Running on Linux and optimal reactor (epoll) already installed.")

    else:
        try:
            from twisted.internet import default as defaultreactor

            defaultreactor.install()
        except Exception as e:
            log.err("WARNING: Could not install default Twisted reactor for this platform ({0}).".format(e))
开发者ID:kampka,项目名称:AutobahnPython,代码行数:86,代码来源:choosereactor.py

示例11: install_optimal_reactor

def install_optimal_reactor(verbose=False):
    """
    Try to install the optimal Twisted reactor for this platform.

    :param verbose: If ``True``, print what happens.
    :type verbose: bool
    """
    log = txaio.make_logger()

    import sys
    from twisted.python import reflect

    # determine currently installed reactor, if any
    ##
    if "twisted.internet.reactor" in sys.modules:
        current_reactor = reflect.qual(sys.modules["twisted.internet.reactor"].__class__).split(".")[-1]
    else:
        current_reactor = None

    # depending on platform, install optimal reactor
    ##
    if "bsd" in sys.platform or sys.platform.startswith("darwin"):

        # *BSD and MacOSX
        ##
        if current_reactor != "KQueueReactor":
            try:
                from twisted.internet import kqreactor

                kqreactor.install()
            except:
                log.critical("Running on *BSD or MacOSX, but cannot install kqueue Twisted reactor")
                log.warn("{tb}", tb=traceback.format_exc())
            else:
                log.debug("Running on *BSD or MacOSX and optimal reactor (kqueue) was installed.")
        else:
            log.debug("Running on *BSD or MacOSX and optimal reactor (kqueue) already installed.")

    elif sys.platform in ["win32"]:

        # Windows
        ##
        if current_reactor != "IOCPReactor":
            try:
                from twisted.internet.iocpreactor import reactor as iocpreactor

                iocpreactor.install()
            except:
                log.critical("Running on Windows, but cannot install IOCP Twisted reactor")
                log.warn("{tb}", tb=traceback.format_exc())
            else:
                log.debug("Running on Windows and optimal reactor (ICOP) was installed.")
        else:
            log.debug("Running on Windows and optimal reactor (ICOP) already installed.")

    elif sys.platform.startswith("linux"):

        # Linux
        ##
        if current_reactor != "EPollReactor":
            try:
                from twisted.internet import epollreactor

                epollreactor.install()
            except:
                log.critical("Running on Linux, but cannot install Epoll Twisted reactor")
                log.warn("{tb}", tb=traceback.format_exc())
            else:
                log.debug("Running on Linux and optimal reactor (epoll) was installed.")
        else:
            log.debug("Running on Linux and optimal reactor (epoll) already installed.")

    else:
        try:
            from twisted.internet import default as defaultreactor

            defaultreactor.install()
        except:
            log.critical("Could not install default Twisted reactor for this platform")
            log.warn("{tb}", tb=traceback.format_exc())

    from twisted.internet import reactor

    txaio.config.loop = reactor
开发者ID:Jenselme,项目名称:AutobahnPython,代码行数:84,代码来源:choosereactor.py

示例12: install_optimal_reactor

def install_optimal_reactor(verbose=False):
    """
    Try to install the optimal Twisted reactor for platform.

    :param verbose: If ``True``, print what happens.
    :type verbose: bool
    """
    import sys
    from twisted.python import reflect
    import txaio
    txaio.use_twisted()  # just to be sure...
    # XXX should I configure txaio.config.loop in here too, or just in
    # install_reactor()? (I am: see bottom of function)

    # determine currently installed reactor, if any
    ##
    if 'twisted.internet.reactor' in sys.modules:
        current_reactor = reflect.qual(sys.modules['twisted.internet.reactor'].__class__).split('.')[-1]
    else:
        current_reactor = None

    # depending on platform, install optimal reactor
    ##
    if 'bsd' in sys.platform or sys.platform.startswith('darwin'):

        # *BSD and MacOSX
        ##
        if current_reactor != 'KQueueReactor':
            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 ({0}) to use kqueue reactor".format(sys.version))
                from twisted.internet import kqreactor
                kqreactor.install()
            except Exception as e:
                print("WARNING: Running on *BSD or MacOSX, but cannot install kqueue Twisted reactor ({0}).".format(e))
            else:
                if verbose:
                    print("Running on *BSD or MacOSX and optimal reactor (kqueue) was installed.")
        else:
            if verbose:
                print("Running on *BSD or MacOSX and optimal reactor (kqueue) already installed.")

    elif sys.platform in ['win32']:

        # Windows
        ##
        if current_reactor != 'IOCPReactor':
            try:
                from twisted.internet.iocpreactor import reactor as iocpreactor
                iocpreactor.install()
            except Exception as e:
                print("WARNING: Running on Windows, but cannot install IOCP Twisted reactor ({0}).".format(e))
            else:
                if verbose:
                    print("Running on Windows and optimal reactor (ICOP) was installed.")
        else:
            if verbose:
                print("Running on Windows and optimal reactor (ICOP) already installed.")

    elif sys.platform.startswith('linux'):

        # Linux
        ##
        if current_reactor != 'EPollReactor':
            try:
                from twisted.internet import epollreactor
                epollreactor.install()
            except Exception as e:
                print("WARNING: Running on Linux, but cannot install Epoll Twisted reactor ({0}).".format(e))
            else:
                if verbose:
                    print("Running on Linux and optimal reactor (epoll) was installed.")
        else:
            if verbose:
                print("Running on Linux and optimal reactor (epoll) already installed.")

    else:
        try:
            from twisted.internet import default as defaultreactor
            defaultreactor.install()
        except Exception as e:
            print("WARNING: Could not install default Twisted reactor for this platform ({0}).".format(e))

    from twisted.internet import reactor
    txaio.config.loop = reactor
开发者ID:Avnerus,项目名称:AutobahnPython,代码行数:86,代码来源:choosereactor.py

示例13:

USA

"""

# BSD and Mac OS X, kqueue
try:
    from twisted.internet import kqreactor as event_reactor
except:
    # Linux 2.6 and newer, epoll
    try:
        from twisted.internet import epollreactor as event_reactor
    except:
        # Linux pre-2.6, poll
        from twisted.internet import pollreactor as event_reactor

event_reactor.install()

from convergence.TargetPage import TargetPage
from convergence.ConnectChannel import ConnectChannel
from convergence.ConnectRequest import ConnectRequest


from OpenSSL import SSL
from twisted.enterprise import adbapi
from twisted.web import http
from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.internet import reactor

import sys, string, os, getopt, logging, pwd, grp, convergence.daemonize
开发者ID:Telarian,项目名称:Convergence,代码行数:30,代码来源:convergence-notary.py


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