我对Python很新。我有一些代码使用Thread
应停止,直到符合条件。等到条件满足为止
当我在控制台中按下键1
脚本停止,而不是在条件test1 == 1:
条件下运行的部分。
当条件满足时,我想运行脚本每个线程只有一次与现有的会话。
代码:
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')
'测试1 = 0 ...而(test1的== 1):',循环永远不会运行,因为'test1'不等于1 –
'while'并不意味着'wait' –
在脚本的最后一行,你可以看到,我设置了test1 = 1,所以循环应该运行,然后 – Dking1199