我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用twisted.internet.defer.execute()。
def __getattr__(self, name): """ Pass attributes through to the real L{BrokerServer}, after checking that they're encodable with AMP. """ original = getattr(self.broker_server, name, None) if (name in get_remote_methods(self.broker_server) and original is not None and callable(original) ): def method(*args, **kwargs): for arg in args: assert MethodCallArgument.check(arg) for k, v in iteritems(kwargs): assert MethodCallArgument.check(v) return execute(original, *args, **kwargs) return method else: raise AttributeError(name)
def loadModel(self, path, request): """Load a model, for the given path and request. @rtype: L{Deferred} """ from twisted.internet.defer import execute return execute(self.loadModelNow, path, request)
def __init__(self, redis_address): self.db = get_redis_connection(redis_address) if redis_address == 'fake': # fakeredis is not thread safe self.defer_func = defer.execute else: self.defer_func = threads.deferToThread
def listen(self, stdioProtocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen on stdin/stdout """ return defer.execute(self._stdio, stdioProtocolFactory.buildProtocol(PipeAddress()), reactor=self._reactor)
def listen(self, protocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen on a TCP socket """ return defer.execute(self._reactor.listenTCP, self._port, protocolFactory, backlog=self._backlog, interface=self._interface)
def listen(self, protocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen for SSL on a TCP socket. """ return defer.execute(self._reactor.listenSSL, self._port, protocolFactory, contextFactory=self._sslContextFactory, backlog=self._backlog, interface=self._interface)
def listen(self, protocolFactory): """ Implement L{IStreamServerEndpoint.listen} to listen on a UNIX socket. """ return defer.execute(self._reactor.listenUNIX, self._address, protocolFactory, backlog=self._backlog, mode=self._mode, wantPID=self._wantPID)