title: Python: Change variable value from another thread
body: <p>Why does the value of my_string not change?</p>
  
  <p>I'm running two threads from two different modules, and module 2 accesses the "set_string" of module 1 in order to change the value of "my_string", but when module 1 prints the string, its empty.</p>
  
  <p>First module:</p>
  
  <pre><code>from threading import Thread
  import Module2 as M2
  import time
  
  my_string = ""
  
  
  def set_string(string):
      global my_string
      my_string = string
  
  
  def mainloop1():
      global my_string
      while True:
          print("Module 1: ", my_string)
          time.sleep(1)
  
  if __name__ == '__main__':
      thread = Thread(target=M2.mainloop2)
      thread.start()
      mainloop1()
  </code></pre>
  
  <p>Second module:</p>
  
  <pre><code>import Module1 as M1
  import time
  import random
  
  
  def mainloop2():
      while True:
          string = str(random.randint(0, 100))
          print("Module 2: ", string)
          M1.set_string(string)
          time.sleep(1)
  </code></pre>