title: how to share global variables across threads in python?
body: <p>I want to end a loop running in a separate thread using a global variable. but this code does not seem to stop the thread in loop. I expect the program not to print any more '.' after 2 seconds, but it still runs indefinitely.</p>
  
  <p>Am I doing something fundamentally wrong here?</p>
  
  <pre><code>import time
  import threading
  run = True
  
  def foo():
      while run:
          print '.',
  
  t1 = threading.Thread(target=foo)
  t1.run()
  time.sleep(2)
  run = False
  print 'run=False'
  while True:
      pass
  </code></pre>