title: Confusion regarding the output of threads in python
body: <p>I am currently working with python v.2.7 on windows 8.</p>
  
  <p>My programme is using threads. I am providing a name to these threads during their creation. The first thread is named <code>First-Thread</code> and second one is named <code>Second-Thread</code>. The threads execute a method named as <code>getData()</code> that does the following:</p>
  
  <ul>
  <li>makes the current thread to sleep for some time</li>
  <li>calls the <code>compareValues()</code></li>
  <li>retrieve the information from the <code>compareValues</code>() and adds them to a
  list called <code>myList</code></li>
  </ul>
  
  <p>The <code>compareValues()</code> does the following:</p>
  
  <ul>
  <li>generates a random number</li>
  <li>checks if it is less than 5 or if it is greater than or equal to 5
  and yields the result along with the current thread's name</li>
  </ul>
  
  <p>I save the results of these threads to a list named as <code>myList</code> and then finally print this <code>myList</code>.</p>
  
  <p><strong>Problem</strong>: Why I never see the <code>Second-Thread</code> in <code>myList</code>? I don't understand this behavior. Please try to execute this code to see the output in order to understand my problem.</p>
  
  <p><strong>Code</strong>:</p>
  
  <pre><code>import time
  from random import randrange
  import threading
  
  myList = []
  def getData(i):
          print "Sleep for %d"%i
          time.sleep(i)
          data = compareValues()
          for d in list(data):
              myList.append(d)
  
  def compareValues():
          number = randrange(10)
          if number &gt;= 5:
               yield "%s: Greater than or equal to 5: %d  "%(t.name, number)
          else:
               yield "%s: Less than 5: %d  "%(t.name, number)
  
  threadList = []
  wait = randrange(10)+1
  t = threading.Thread(name = 'First-Thread', target = getData, args=(wait,))
  threadList.append(t)
  t.start()
  wait = randrange(3)+1
  t = threading.Thread(name = 'Second-Thread', target = getData, args=(wait,))
  threadList.append(t)
  t.start()
  for t in threadList:
      t.join()
  print
  print "The final list"
  print myList
  </code></pre>
  
  <p><strong>Sample output</strong>:</p>
  
  <pre><code>Sleep for 4Sleep for 1
  
  The final list
  ['First-Thread: Greater than or equal to 5: 7  ', 'First-Thread: Greater than or equal to 5: 8  ']
  </code></pre>
  
  <p>Thank you for your time.</p>