[Twisted-Python] Problem with runInteraction and passing a dict variable

Ron Arts ron.arts at netland.nl
Sun Oct 29 17:38:16 EST 2006


thanks! Being an experienced C and PHP programmer, the
fact that python always seems to pass around the original
variable took me by surprise, I used block.copy() and the problem
went away.


Jean-Paul Calderone schreef:
> On Sun, 29 Oct 2006 20:57:21 +0100, Ron Arts <ron.arts at netland.nl> wrote:
>> Hello,
>> I am both a python and twisted beginner, but I think I have found
>> a problem in twisted. See the code below.
>> The handle_PeerStatus function receives a dict wich contains
>> some info. Then it calls runInteraction with that variable.
>> When the UpdatePeerStatus function is run, block is empty.
>> I did some investigating, it seems that UpdatePeerStatus is
>> run using a workerthread which takes it values from a Queue.
>> When the dict is pushed onto the Queue, it is valid, when
>> when it is popped by the worker thread, the var is empty.
>> Can anybody give me tips to solve this? Am I absolutely
>> missing something and on the wring track or should I enter a bug?
> Simply going through the queue won't mutate the dictionary.  Are
> you certain no other part of your code is manipulating it?  One
> way you could check this is by passing a _copy_ of block to
> runInteraction so that modifications to the original won't affect
> it.  If this results in things working as you expect, then you've
> found the problem.
> In general, you should _not_ be touching the same objects from more
> than one thread.  Passing an object to another thread is fine, but
> when you do so, you give up all rights to further inspect or modify
> that object, until such time as the other thread chooses to give it
> back to you (whereafter it should likewise give up those privileges).
> Jean-Paul
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ron.arts.vcf
Type: text/x-vcard
Size: 270 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20061029/880df1c8/attachment.vcf 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3403 bytes
Desc: S/MIME Cryptographic Signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20061029/880df1c8/attachment.bin 

More information about the Twisted-Python mailing list