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

Jean-Paul Calderone exarkun at divmod.com
Sun Oct 29 16:48:31 EST 2006

On Sun, 29 Oct 2006 20:57:21 +0100, Ron Arts <ron.arts at netland.nl> wrote:
>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).


More information about the Twisted-Python mailing list