F
F
f1awe2021-09-19 11:35:50
Python
f1awe, 2021-09-19 11:35:50

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)


Also, at the beginning of the program I have variables:
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")


On pythonanywhere, after 3-5 iterations, the program just stops. What to do?
6146f62de6177618812354.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-09-22
@f1awe

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 question

Ask a Question

731 491 924 answers to any question