[Twisted-Python] Asynchronously reading posted data

Paul Wiseman poalman at gmail.com
Wed Sep 4 11:48:40 MDT 2013


I'm still pretty new to twisted and feel I'm slowly getting the hang of it,
enough to realise that this line of code is probably going to block and not
do me any favours, the line is the first line in a resource.Resource
render_POST.

json_request = json.loads(request.content.read())

The resource.Resource is a child of another resource which is passed to
server.Site which is passed to internent.TCPServer.

The problem is I can't work out how I can read the post data from the
request in an async way.

I have a feeling I need to implement a protocol, I'm guessing a
LineReceiver but I can't figure out how I'd tie that in with my current
solution or specifically how the LineReceiver would even read
asynchronously to be honest..

Maybe the read is fine? I need the whole post data to do anything useful I
guess as I can't string to a json decoder that I'm aware of. Just it will
block everything up while I read, which shouldn't be long but I guess I'm
bound to the speed of the person posting.

Thanks all!

Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20130904/9c28960f/attachment.html>


More information about the Twisted-Python mailing list