Re: Non-blocking webserver - what am I doing wrong?
On Apr 25, 2005, at 5:21 PM, Dave Gray wrote:
I'm trying to get a simple webserver working using twisted. It works, to some extent, serves pages and all, but it blocks until the reactor.callLater(...) is done... what am I doing wrong?
Nothing, it doesn't block, it works perfectly. Your web browser is likely confusing you by reusing the same open connection to the server. Try using multiple web browsers, or else a command line utility.
# CODE from twisted.web import server from twisted.web.resource import Resource from twisted.internet import reactor, defer
import pprint dump = pprint.PrettyPrinter(indent=4).pformat def requestDebug(r): r.write('<pre>'+ dump(r.headers) +'</pre>') reactor.callLater(5, r.finish)
class NonBlock(Resource): """ I should be a non-blocking resource that takes 5s to load. Instead, each request waits for any others to finish. """ def getChild(self, path, request): return self isLeaf=False def render_GET(self, request): d = defer.Deferred() d.addCallback(requestDebug) d.callback(request) return server.NOT_DONE_YET
from twisted.application import service, internet application = service.Application("nonblock") internet.TCPServer(8080, server.Site(NonBlock()) ).setServiceParent(application)
James Y Knight wrote:
On Apr 25, 2005, at 5:21 PM, Dave Gray wrote:
I'm trying to get a simple webserver working using twisted. It works, to some extent, serves pages and all, but it blocks until the reactor.callLater(...) is done... what am I doing wrong?
Nothing, it doesn't block, it works perfectly. Your web browser is likely confusing you by reusing the same open connection to the server. Try using multiple web browsers, or else a command line utility.
*sigh*, thanks. Is that an FAQ? :)
participants (2)
-
Dave Gray
-
James Y Knight