title: Python: sharing message between processes
body: <p>I've been searching for answer to that problem for few hours but couldn't solve it so I have to post here this question, I'm sure it's trivial.</p>
  
  <p>The project I work with has many classes and threads and I'm adding small classes to it. Those classes are executed in different threads with project's engine but I need them to synchronize between themselves - that is class A should be able to send a message to class B. They are also in different modules.</p>
  
  <p><strong>EDIT2: there is a new explanation of this question: look at the bottom.</strong></p>
  
  <p>I am really very beginner in python and I tried to solve this by sharing queue object (Queue.Queue()) and examining it's content in endless loops, I made very simple module with this object and methods get and put:</p>
  
  <p>messenger module:</p>
  
  <pre><code>import Queue
  
  MessageQueue = Queue.Queue()
  
  def GetMessage():
      return MessageQueue.get()
  
  def PutMessage(message):
      MessageQueue.put(message)
      return
  </code></pre>
  
  <p>and use it in two different classes (import messenger), but since it's not global variable, I assume that 'MessageQueue' object has different instances in different classes. Because those classes seems working on different queues.</p>
  
  <p>How to synchronize two classes with such object between (maybe there is a pretier way instead just making this queue global)?</p>
  
  <p><strong>EDIT1 - here are classes:</strong></p>
  
  <p>class A:</p>
  
  <pre><code>from utils import messenger as m
  
  class Foo():
  
  [...]
  
  def foo():
  
      [...]
      m.put(message)
  </code></pre>
  
  <p>class B:</p>
  
  <pre><code>from utils import messenger
  
  class Bar():
  
  [...]
  
  def bar():
  
      [...]
      while True:           
         print(str(m.get()))
  </code></pre>
  
  <p><strong>EDIT2: Since I understand my problem a bit better now, here is an update:</strong></p>
  
  <p>Both classes are run as distinct programs in different processes (what may explain why the are not sharing global variables :)). </p>
  
  <p>So the problem remains: how to synchronize between two different programs? The only solution I think of is to make a file on a disc and read it between processes, but it seems very unreliable (locks etc.) and slow. </p>
  
  <p>Can you suggest me different approach?</p>