Python - problems with shared variable
<p>I'd like to use a shared queue from multiple threads and modules. I have the following Python code:</p>

<pre><code># moda.py

import queue
import modb

q = queue.Queue()

def myPut(x):
    q.put(x)

def main():
    print('moda:', str(id(q)))
    modb.go()
    q.get()


if __name__ == '__main__':
    main()
</code></pre>

<p>and</p>

<pre><code># modb.py

import moda
import threading


def something():
    print('modb:', str(id(moda.q)))
    moda.myPut('hi')


def go():
    threading.Thread(target = something).start()
</code></pre>

<p><code>something</code> gets called on thread 1, <code>somethingElse</code> gets called on thread 2. The addresses of <code>q</code> are different in these two methods - which is why the call to <code>get</code> never returns. How can I avoid this? Is it because of the cyclic import or because of multithreading?</p>
