[Twisted-web] cooperate and keeping data integrity in response
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
> >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
> >subsequent requests.
> >The way I see it the functions to read data and and store it in my list
> >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
> >I will need to block each request and not service another request until
> >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.
> Twisted-web mailing list
> Twisted-web at twistedmatrix.com
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-web