def googleAMPClient(): from twisted.internet.protocol import ClientCreator cc = ClientCreator(reactor, AMP) ampConnection = blockOn(cc.connectTCP("localhost", 1030)) result = blockOn(ampConnection.callRemote(FetchGoogle)) if "I'm Feeling Lucky" in result["google"]: print "Google AMP Client test succeeded" else: print "Google AMP client test failed :-(" ampConnection.transport.loseConnection()
def gConnectTCP(host, port, reactor=None): """ Return a L{GreenletTransport} connected to the given host and port. This function must NOT be called from the reactor's greenlet. """ from corotwine.defer import blockOn current = greenlet.getcurrent() assert current is not MAIN, \ "Don't run gConnectTCP from the reactor greenlet." if reactor is None: from twisted.internet import reactor d = Deferred() f = ClientFactory() f.protocol = lambda: _GreenletClientProtocol(d, current) reactor.connectTCP(host, port, f) return blockOn(d)
def fetchGoogle(self): return {"google": blockOn(getPage("http://google.com/"))}
def fetchGoogle(transport): result = blockOn(getPage("http://google.com/")) transport.write(result)
def greeny(): events.append("waiting") try: blockOn(deferred) except Exception, e: events.append(e)
def greeny(): events.append("waiting") events.append(blockOn(deferred))
def catcher(): events.append("waiting") try: blockOn(deferred) except Exception, e: events.append(e)