[Twisted-web] cooperate and keeping data integrity in response

John Aherne johnaherne at rocs.co.uk
Mon Jan 16 10:33:06 EST 2012

On Mon, Jan 16, 2012 at 1:54 PM, <exarkun at twistedmatrix.com> wrote:

> On 14 Jan, 09:30 am, johnaherne at rocs.co.uk wrote:
> >I have been looking at JPCalderones example of using web.request with
> >which seems much like what I want.
> >
> >One thing I am not clear about is if I get a lot of queries coming in
> >more
> >or less simultaneously and I am using cooperate to allow other
> >functions to
> >run, will I need to guard against my data in a list being overwritten
> >by
> >subsequent requests.
> >
> >The way I see it the functions to read data and and store it in my list
> >are
> >in danger of impacting each other.
> >
> >The response is being built cooperatively bit by bit to permit other
> >functions to run so it could happen that the next request overwrites my
> >list where the database query is being stored.
> Any time you have shared mutable state, you have this possibility.  You
> do need to take measures to avoid making one request destroy the state
> associated with another request.
> >If this is a danger, then I need to prevent this, which seems to imply
> >that
> >I will need to block each request and not service another request until
> >the
> >previous one has completed.
> Serializing (ie, not processing a second request until the first is
> completed) processing is one way to accomplish this.
> However, another way to accomplish it is to not have shared mutable
> state.  A quick skim of your code suggests you don't actually have much,
> if any, shared mutable state.
> The list holding your database results is a local variable, and each
> request builds its own (as far as I can tell).  There is no danger of
> different requests interfering with each other in this case.
> Jean-Paul
> _______________________________________________
> Twisted-web mailing list
> Twisted-web at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Thanks for the reply.

I think I must have been asleep when I asked this.

Someone else pointed this out to me earlier on but I did not have time to
get to a computer before you replied.

Thanks anyway. I shall glue this to me screen for the next week or so.

John Aherne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20120116/de92d601/attachment.htm 

More information about the Twisted-web mailing list