i want to start a function after a timeout in a While true loop, but the code dont execute anything and jumps out the loop and i dont know why :/
Here is my Code
import requests
from threading import Timer
def timeout(flag):
print("New Request")
statuscode = requests.get("http://adslkfhdsjf.de").status_code
if statuscode == 200 and flag == 0:
print("Service available")
#Testzwecke
print("Flag: ", flag)
flag = 0
#Poste result to Backend
elif statuscode == 200 and flag == 1:
print("Service is available now")
print("Flag: ", flag)
flag = 0
#Email an User
#Post Request
elif statuscode != 200 and flag == 0:
print("Service is not available")
#Testzwecke
print("Flag: ", flag)
flag = 1
#Email to User
#Post Request
else:
print("Service is not available")
#Testzwecke
print("Flag: ", flag)
#Post Request
Timer(10, timeout, flag)
timeout(0)
I want that timeout is executed for example every 10 seconds. So every 10 second one condition from the function timeout() will be executed.
But its not working so far, the console output is nothing :/
mainfunction and never calls it. Is that true for your real code as well?flagand the definition oftimeoutoutside themain.main()at the end of your script), you'll have a whole new problem: you're creating and calling a newtimeoutfunction over and over as fast as possible. Each one creates aTimer, which creates a new thread. So you're very quickly going to create more threads than your OS can handle. If you're lucky, you'll get an error. If you're not lucky, your system will slow to a crawl, and take minutes to recover even after you manage to kill the script.flaginmainwill be hidden by theflagintimeout, but the same would be true for a globalflag.