title: python global variable inside a thread
body: <p>The story begin with two threads and a global variable that change.. a lot of time :)</p>
  
  <p>Thread number one (for simplicity we will call t1) generates a random number and store it in a global variable GLB.</p>
  
  <p>Thread number two (aka t2) check the value of the global variable and when it reaches a value starts to print his value until a period of time.</p>
  
  <p>BUT if t1 changes the value of that global variable, also change the value inside the loop and I don't want this!</p>
  
  <p>I try to write pseudocode:</p>
  
  <pre><code>import random
  import time
  import threading
  
  
  GLB = [0,0]
  
  #this is a thread 
  def t1():
      while True:
          GLB[0] = random.randint(0, 100)
          GLB[1] = 1
          print GLB
          time.sleep(5)
  
  
  #this is a thread 
  def t2():
      while True:
          if GLB[0]&lt;=30:
              static = GLB
              for i in range(50):
                  print i," ",static
                  time.sleep(1)
  
  
  
  
  a = threading.Thread(target=t1)
  a.start()
  
  
  b = threading.Thread(target=t2)
  b.start()
  
  while True:
      time.sleep(1)
  </code></pre>
  
  <p>The question is: why variable static change inside the loop for? It should be remain constant unitl it escapes from loop! 
  Could I create a lock to the variable? Or there is any other way to solve the problem? </p>
  
  <p>Thanks regards. </p>