holy moly - you're right! This fool will sleep so much better...a million
thanks.
On Thu, Dec 17, 2015 at 12:09 AM, Amber "Hawkie" Brown <
hawk...@atleastfornow.net> wrote:
>
> > On 17 Dec 2015, at 08:11, Kevin Mcintyre <kebi...@gmail.com> wrote:
> >
> > Hey - I'm confused, so nothing new :) ...but I'm running at this example
> and I'm scratching my head.
> >
> >
> http://twistedmatrix.com/documents/current/web/howto/web-in-60/asynchronous-deferred.html
> >
> > I would've thought 2 requests could be served simultaneously, but when I
> fire off 2 requests the first received gets it's response after 5 seconds,
> while the second response takes 10 seconds.
> >
> > I think I understand what's happening, but I don't know why...and I
> would love an example where the subsequent request doesn't have to wait for
> the first request to finish.
> >
> > Thanks,
> > Kevin
>
>
> I've ran into this before -- browsers sometimes rate-limit requests, and
> won't actually send the second request until the first is done, over the
> same connection, rather than making a second TCP connection -- try using
> cURL or wget, which has no such limitation, and see if it works any better.
>
> - Amber
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python@twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>
from twisted.internet.task import deferLater
from twisted.web.resource import Resource
from twisted.web.server import NOT_DONE_YET, Site
from twisted.internet import reactor, defer
from twisted.web.client import getPage
import time
class DelayedResource(Resource):
isLeaf = True
def _delayedRender(self, request):
request.write(str(int(time.time())))
request.finish()
def render_GET(self, request):
d = deferLater(reactor, 5, lambda: request)
d.addCallback(self._delayedRender)
return NOT_DONE_YET
def results(res, init_time):
print init_time, res[0][1], res[1][1], int(time.time())
def done_or_error(ans = None):
print 'done_or_error:', ans
reactor.stop()
def double_request():
init_time = int(time.time())
dl = defer.DeferredList([getPage('http://localhost:8080'), getPage('http://localhost:8080')])
dl.addCallback(results, init_time)
dl.addBoth(done_or_error)
if __name__ == '__main__':
reactor.listenTCP(8080, Site(DelayedResource()))
reactor.callWhenRunning(double_request)
print 'start reactor'
reactor.run()
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python