當前位置: 首頁>>代碼示例>>Python>>正文


Python twisted.internet方法代碼示例

本文整理匯總了Python中tornado.platform.twisted.internet方法的典型用法代碼示例。如果您正苦於以下問題:Python twisted.internet方法的具體用法?Python twisted.internet怎麽用?Python twisted.internet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.platform.twisted的用法示例。


在下文中一共展示了twisted.internet方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: install

# 需要導入模塊: from tornado.platform import twisted [as 別名]
# 或者: from tornado.platform.twisted import internet [as 別名]
def install(io_loop=None):
    """Install this package as the default Twisted reactor.

    ``install()`` must be called very early in the startup process,
    before most other twisted-related imports. Conversely, because it
    initializes the `.IOLoop`, it cannot be called before
    `.fork_processes` or multi-process `~.TCPServer.start`. These
    conflicting requirements make it difficult to use `.TornadoReactor`
    in multi-process mode, and an external process manager such as
    ``supervisord`` is recommended instead.

    .. versionchanged:: 4.1
       The ``io_loop`` argument is deprecated.

    """
    if not io_loop:
        io_loop = tornado.ioloop.IOLoop.current()
    reactor = TornadoReactor(io_loop)
    from twisted.internet.main import installReactor
    installReactor(reactor)
    return reactor 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:23,代碼來源:twisted.py

示例2: resolve

# 需要導入模塊: from tornado.platform import twisted [as 別名]
# 或者: from tornado.platform.twisted import internet [as 別名]
def resolve(self, host, port, family=0):
        # getHostByName doesn't accept IP addresses, so if the input
        # looks like an IP address just return it immediately.
        if twisted.internet.abstract.isIPAddress(host):
            resolved = host
            resolved_family = socket.AF_INET
        elif twisted.internet.abstract.isIPv6Address(host):
            resolved = host
            resolved_family = socket.AF_INET6
        else:
            deferred = self.resolver.getHostByName(utf8(host))
            resolved = yield gen.Task(deferred.addCallback)
            if twisted.internet.abstract.isIPAddress(resolved):
                resolved_family = socket.AF_INET
            elif twisted.internet.abstract.isIPv6Address(resolved):
                resolved_family = socket.AF_INET6
            else:
                resolved_family = socket.AF_UNSPEC
        if family != socket.AF_UNSPEC and family != resolved_family:
            raise Exception('Requested socket family %d but got %d' %
                            (family, resolved_family))
        result = [
            (resolved_family, (resolved, port)),
        ]
        raise gen.Return(result) 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:27,代碼來源:twisted.py

示例3: install

# 需要導入模塊: from tornado.platform import twisted [as 別名]
# 或者: from tornado.platform.twisted import internet [as 別名]
def install():
    """Install this package as the default Twisted reactor.

    ``install()`` must be called very early in the startup process,
    before most other twisted-related imports. Conversely, because it
    initializes the `.IOLoop`, it cannot be called before
    `.fork_processes` or multi-process `~.TCPServer.start`. These
    conflicting requirements make it difficult to use `.TornadoReactor`
    in multi-process mode, and an external process manager such as
    ``supervisord`` is recommended instead.

    .. versionchanged:: 5.0
       The ``io_loop`` argument (deprecated since version 4.1) has been removed.

    .. deprecated:: 5.1

       This functio will be removed in Tornado 6.0. Use
       ``twisted.internet.asyncioreactor.install`` instead.
    """
    reactor = TornadoReactor()
    from twisted.internet.main import installReactor  # type: ignore
    installReactor(reactor)
    return reactor 
開發者ID:tp4a,項目名稱:teleport,代碼行數:25,代碼來源:twisted.py

示例4: initialize

# 需要導入模塊: from tornado.platform import twisted [as 別名]
# 或者: from tornado.platform.twisted import internet [as 別名]
def initialize(self, reactor=None, **kwargs):
        super(TwistedIOLoop, self).initialize(**kwargs)
        if reactor is None:
            import twisted.internet.reactor
            reactor = twisted.internet.reactor
        self.reactor = reactor
        self.fds = {} 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:9,代碼來源:twisted.py

示例5: resolve

# 需要導入模塊: from tornado.platform import twisted [as 別名]
# 或者: from tornado.platform.twisted import internet [as 別名]
def resolve(self, host, port, family=0):
        # getHostByName doesn't accept IP addresses, so if the input
        # looks like an IP address just return it immediately.
        if twisted.internet.abstract.isIPAddress(host):
            resolved = host
            resolved_family = socket.AF_INET
        elif twisted.internet.abstract.isIPv6Address(host):
            resolved = host
            resolved_family = socket.AF_INET6
        else:
            deferred = self.resolver.getHostByName(utf8(host))
            resolved = yield gen.Task(deferred.addBoth)
            if isinstance(resolved, failure.Failure):
                resolved.raiseException()
            elif twisted.internet.abstract.isIPAddress(resolved):
                resolved_family = socket.AF_INET
            elif twisted.internet.abstract.isIPv6Address(resolved):
                resolved_family = socket.AF_INET6
            else:
                resolved_family = socket.AF_UNSPEC
        if family != socket.AF_UNSPEC and family != resolved_family:
            raise Exception('Requested socket family %d but got %d' %
                            (family, resolved_family))
        result = [
            (resolved_family, (resolved, port)),
        ]
        raise gen.Return(result) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:29,代碼來源:twisted.py

示例6: callFromThread

# 需要導入模塊: from tornado.platform import twisted [as 別名]
# 或者: from tornado.platform.twisted import internet [as 別名]
def callFromThread(self, f, *args, **kw):
        """See `twisted.internet.interfaces.IReactorThreads.callFromThread`"""
        assert callable(f), "%s is not callable" % f
        with NullContext():
            # This NullContext is mainly for an edge case when running
            # TwistedIOLoop on top of a TornadoReactor.
            # TwistedIOLoop.add_callback uses reactor.callFromThread and
            # should not pick up additional StackContexts along the way.
            self._io_loop.add_callback(f, *args, **kw)

    # We don't need the waker code from the super class, Tornado uses
    # its own waker. 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:14,代碼來源:twisted.py

示例7: install

# 需要導入模塊: from tornado.platform import twisted [as 別名]
# 或者: from tornado.platform.twisted import internet [as 別名]
def install(io_loop=None):
    """Install this package as the default Twisted reactor."""
    if not io_loop:
        io_loop = tornado.ioloop.IOLoop.current()
    reactor = TornadoReactor(io_loop)
    from twisted.internet.main import installReactor
    installReactor(reactor)
    return reactor 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:10,代碼來源:twisted.py

示例8: initialize

# 需要導入模塊: from tornado.platform import twisted [as 別名]
# 或者: from tornado.platform.twisted import internet [as 別名]
def initialize(self, reactor=None):
        if reactor is None:
            import twisted.internet.reactor
            reactor = twisted.internet.reactor
        self.reactor = reactor
        self.fds = {}
        self.reactor.callWhenRunning(self.make_current) 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:9,代碼來源:twisted.py

示例9: initialize

# 需要導入模塊: from tornado.platform import twisted [as 別名]
# 或者: from tornado.platform.twisted import internet [as 別名]
def initialize(self, reactor=None, **kwargs):
        super(TwistedIOLoop, self).initialize(**kwargs)
        if reactor is None:
            import twisted.internet.reactor  # type: ignore
            reactor = twisted.internet.reactor
        self.reactor = reactor
        self.fds = {} 
開發者ID:tp4a,項目名稱:teleport,代碼行數:9,代碼來源:twisted.py

示例10: resolve

# 需要導入模塊: from tornado.platform import twisted [as 別名]
# 或者: from tornado.platform.twisted import internet [as 別名]
def resolve(self, host, port, family=0):
        # getHostByName doesn't accept IP addresses, so if the input
        # looks like an IP address just return it immediately.
        if twisted.internet.abstract.isIPAddress(host):
            resolved = host
            resolved_family = socket.AF_INET
        elif twisted.internet.abstract.isIPv6Address(host):
            resolved = host
            resolved_family = socket.AF_INET6
        else:
            deferred = self.resolver.getHostByName(utf8(host))
            fut = Future()
            deferred.addBoth(fut.set_result)
            resolved = yield fut
            if isinstance(resolved, failure.Failure):
                try:
                    resolved.raiseException()
                except twisted.names.error.DomainError as e:
                    raise IOError(e)
            elif twisted.internet.abstract.isIPAddress(resolved):
                resolved_family = socket.AF_INET
            elif twisted.internet.abstract.isIPv6Address(resolved):
                resolved_family = socket.AF_INET6
            else:
                resolved_family = socket.AF_UNSPEC
        if family != socket.AF_UNSPEC and family != resolved_family:
            raise Exception('Requested socket family %d but got %d' %
                            (family, resolved_family))
        result = [
            (resolved_family, (resolved, port)),
        ]
        raise gen.Return(result) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:34,代碼來源:twisted.py

示例11: callFromThread

# 需要導入模塊: from tornado.platform import twisted [as 別名]
# 或者: from tornado.platform.twisted import internet [as 別名]
def callFromThread(self, f, *args, **kw):
        """See `twisted.internet.interfaces.IReactorThreads.callFromThread`"""
        assert callable(f), "%s is not callable" % f
        p = functools.partial(f, *args, **kw)
        self._io_loop.add_callback(p)

    # We don't need the waker code from the super class, Tornado uses
    # its own waker. 
開發者ID:omererdem,項目名稱:honeything,代碼行數:10,代碼來源:twisted.py

示例12: install

# 需要導入模塊: from tornado.platform import twisted [as 別名]
# 或者: from tornado.platform.twisted import internet [as 別名]
def install(io_loop=None):
    """Install this package as the default Twisted reactor."""
    if not io_loop:
        io_loop = tornado.ioloop.IOLoop.instance()
    reactor = TornadoReactor(io_loop)
    from twisted.internet.main import installReactor
    installReactor(reactor)
    return reactor 
開發者ID:omererdem,項目名稱:honeything,代碼行數:10,代碼來源:twisted.py


注:本文中的tornado.platform.twisted.internet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。