[Twisted-Python] How can I keep data integrity in multiple threads environment

Phil Mayers p.mayers at imperial.ac.uk
Mon Dec 12 12:15:17 EST 2005

Kaladan wrote:
> Hello,
> I am new to twisted and I have a few questions: I have implemented a
> TCPServer
> and the associated Factory, which manages data and dispatches treatments
> (According to the tutorial it's not the best solution but actually this is
> not
> the point ;) )
> All of the treatments run in threads and thus use shared data. The allData
> dictionnary is critical since it can be used by multiple threads. How can I
> keep
> the allData integrity ? Does Twisted core provide such facilites or do I
> have to use semaphore or other stuff ?

You have to do it yourself. Twisted is not thread-safe and does not 
provide any thread support beyond the two most basic methods to talk to 
threads: deferToThread/callInThread and callFromThread

More information about the Twisted-Python mailing list