How to pass a dict to a python thread that can be changed from outside of thread without using queue
Question: I would like to have a shared dict between my threads without using Queue. I
did it before by making thread with an object in python but now I want to make
thread with just one function of object not all of it. my simplified code is
as follow:

    
    
     #!/usr/bin/python
     import threading
     import time
    
    
     class WebSocket(threading.Thread):
         def __init__(self, server=1, sock=1, address=1):
             self.s1=server
             self.s2=sock
             self.s3=address
             print "salam"
    
    
         def CheckThread(self):
             self.a={'1':1, '2':2}
             s=threading.Thread(target=self.SockFun, kwargs=self.a)
             s.deamon=True
             s.start()
    
             while(1):
                 self.a['1']=self.a['1']+1
                 time.sleep(1)
    
         def SockFun(self,**kwargs):
             pass
    
     class SimpleEcho(WebSocket):
         def SockFun(self,**kwargs):
             while(1):
                 print kwargs
                 time.sleep(1)
    
         def handleMessage(self):
             self.CheckThread()
    
     s=SimpleEcho()
     s.handleMessage()
    

my printed dict element '1' of kwargs does not increase as expected inside
thread:


Answer: Using the `kwargs` mechanism causes the dict elements to be copied into
`SimpleEcho`. After they are there, changing the original doesn't make a
difference to what is printed. A quick way to see this is to change `print
kwargs` to `print self.a`.

Alternatively you can change `kwargs=self.a` to `kwargs={"argh":self.a}`. This
way, `kwargs` will still be copied, but that copy will contain a reference to
the original `self.a`.

And shouldn't you be using some kind of locking?

