[Twisted-Python] Shared resource manioulation example

vitaly at synapticvision.com vitaly at synapticvision.com
Fri May 28 11:14:43 MDT 2010


Thank you for reply.

I'm calling each update/delete function as a separate Deferred, no  
explicit threads on those functions.

OK than, let's complicated it a bit with "dictionary of lists of  
dictionaries" instead of simple dictionary and let's put it all under  
reactor().

There are 2 incoming requests: one to "update aa1=aval100" and another  
to "delete 'a1'":
a={
   'a1':[{'aa1':'aval1'},{'bb1':'bval1'}],
   'a2':[{'aa2':'aval1'},{'bb2':'bval2'}]
}

So "delete 'a1'" will exec always only after "update aa1=aval100" is done?


Quoting "Allen Short" <washort at twistedmatrix.com>:

> On Fri, May 28, 2010 at 8:46 AM,  <vitaly at synapticvision.com> wrote:
>> I'm looking for a Twisted based example how
>> it should be properly done update/delete of global dictionary's
>> SAME key:value pair from different functions all together.
>> Or by another words, two functions are trying to update the same
>> key:value pair of the same dictionary at the same time, than how to do
>> it properly with Twisted?
>
> Twisted doesn't change anything about Python in this regard. One
> update to the dictionary is going to happen before the other. If these
> updates are being done from different threads, you need some kind of
> synchronization to make them happen in the order you want.
>
> However, if you aren't explicitly using threads in your code, remember
> that Twisted doesn't run your code outside the main thread unless you
> ask it to. So nothing happens at "the same time" -- one function runs,
> then the other.
>
> What problems are you running into?
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>






More information about the Twisted-Python mailing list