I am pretty new to Python. I have some code using Thread which should stop until a condition is met. When I press key 1 in the console the script just stops instead of running the part under the condition test1 == 1:. When the condition is met, I want to run the script only 1 time per Thread with the existing sessions. 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') Continue reading...