title: Wait until condition is met
body: <p>I am pretty new to Python. I have some code using <code>Thread</code> which should stop until a condition is met. </p>
  
  <p>When I press key <code>1</code> in the console the script just stops instead of running the part under the condition <code>test1 == 1:</code>.</p>
  
  <p>When the condition is met, I want to run the script <strong>only 1 time per Thread with the existing sessions</strong>.</p>
  
  <hr>
  
  <p>Code:</p>
  
  <pre><code>  def test()
  
      #some code  
      test1 = 0
  
      while (test1 == 1): #Wait until is set 1 in if __name__ == '__main__': and run the code only 1 time 
          response = session.get('https://www.example.com/')
  
  
          opts = ChromeOptions()
          opts.add_experimental_option("detach", True)
          driver = Chrome(chrome_options=opts)
  
          driver.get(response.url + '#/checkout/login')
          print "Checking Out..."
          test1+=1
  
  def Main():
          t1 = Thread(target=test, args=())
          t1.start()
  
  
  if __name__ == '__main__':
      test = input('How many tasks you want to start? \n')
      for i in range(test):
          Main()
      test1 = input('Proceed? if yes press 1 \n')
  </code></pre>