Answer the question
In order to leave comments, you need to log in
While True stops working after a while?
I have a piece of code that constantly checks if it's time to do something (these actions should be repeated every 15 minutes and every 8 hours)
I use the while True construct and in it I have:
while True:
if profit_time <= datetime.datetime.now():
collect_profit()
profit_time = profit_time + datetime.timedelta(hours=8)
info_log(f'| Деньги будут собраны в {profit_time}')
elif underwork_time <= datetime.datetime.now():
underwork()
pets_battle()
underwork_time = datetime.datetime.now() + datetime.timedelta(minutes=15)
info_log(f'| Следующие действия будут выполнены {underwork_time}')
else:
time.sleep(2)
underwork_time = datetime.datetime.strptime(start_date, "%Y-%m-%d %H:%M:%S") + datetime.timedelta(minutes=15)
profit_time = str(datetime.datetime.now().strftime('%Y-%m-%d')) + str(datetime.datetime.now().strftime(' %H:%M:59'))
profit_time = datetime.datetime.strptime(profit_time, "%Y-%m-%d %H:%M:%S")
Answer the question
In order to leave comments, you need to log in
Press CTRL+C and see the traceback. See what exactly was running at that moment.
And do you have HTTP requests to external servers there, for example, through requests? So when no timeouts are specified, these calls can hang during the connection setup phase without causing an error.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question