Loop not working - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Loop not working (/thread-28413.html) |
Loop not working - Nonameface - Jul-18-2020 while 1: import webbrowser chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s' webbrowser.get(chrome_path).open('https://www.halowaypoint.com/en-us/news') from time import sleep import os sleep(30) os.system("taskkill /im chrome.exe /f")Idk why it wont keep looping, any help? RE: Loop not working - buran - Jul-18-2020 sleep(30) will make it wait 30 seconds RE: Loop not working - Nonameface - Jul-18-2020 I know, but it still wont loop? RE: Loop not working - ndc85430 - Jul-18-2020 How are you determining that the loop isn't running? Also, you don't need to import on every iteration; those can just be at the top of your file.
RE: Loop not working - Nonameface - Jul-18-2020 It doesn't kill chrome, and start again... RE: Loop not working - deanhystad - Jul-18-2020 Sounds like "it doesn't kill chrome" is the problem, not the loop. Or maybe it does kill chrome and you just don't see that. What happens if you add a delay after killing chrome and maybe sprinkle a few print statements here and there to monitor progress. RE: Loop not working - Nonameface - Jul-19-2020 No i see it. Shouldn't it just work? RE: Loop not working - deanhystad - Jul-19-2020 After it opens up the website it waits for the chrome process to end, then it does the wait. This was immediately obvious when I modified the program like this: import webbrowser from time import sleep import os while 1: print('start chrome') chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s' print('going to website') webbrowser.get(chrome_path).open('https://www.halowaypoint.com/en-us/news') print('sleep') sleep(10) print('kill chrome') os.system("taskkill /im chrome.exe /f") print('Wait again') sleep(10) print('repeat')It would be nice if programs worked, but people are stupid and make mistakes. That is why debugging is just as important as coding. I was stupid and could not spot why the program didn't work just by looking, but a few minutes spent adding some debug code exposed the problem right away. RE: Loop not working - snippsat - Jul-19-2020 Also try not to use os.system() anymore.subprocess replace it. import subprocess subprocess.run("taskkill /im chrome.exe /f") # Or the safer way if think of shell injection vulnerabilities #subprocess.run(['taskkill', '/im', 'chrome.exe', '/f'], shell=False) |