[Twisted-Python] Request for help: throttling serving of static content
Tomorrow I'm giving a talk to provide an introduction to asynchronous
programming. I'll be mentioning Twisted in passing, but the meat of the
talk will be about writing a web crawler for finding broken links, first
using single-threaded blocking code, then multi-threaded blocking code,
before demonstrating a non-blocking solution using a select loop. I can
make the code and slides available if there's interest.
For this to be effective, I was planning on writing a very slow webserver
to serve static content locally. I'd expected I'd be able to simply wrap
an instance of twisted.web.static.Site in a ThrottlingFactory, and serve
away:
import sys
from twisted.internet import reactor
from twisted.internet.endpoints import TCP4ServerEndpoint
from twisted.protocols.policies import ThrottlingFactory
from twisted.web.server import Site
from twisted.web.static import File
from twisted.python import log
if __name__ == '__main__':
log.startLogging(sys.stdout)
resource = File(sys.argv[1])
factory = Site(resource)
endpoint = TCP4ServerEndpoint(reactor, 4321)
endpoint.listen(ThrottlingFactory(factory, maxConnectionCount=3,
readLimit=20, writeLimit=20))
reactor.run()
However, this fails with the following error because I've not registered a
producer with my ThrottlingProtocol:
2012-11-05 21:01:34+0000 [-] Throttling writes on
participants (4)
-
exarkun@twistedmatrix.com
-
Itamar Turner-Trauring
-
Peter Inglesby
-
Phil Mayers