pythontimewhile-loopjupyter-notebook

Run Python Program Until Specific Time


I want to run my program in jupyter notebook and this program stops at specific time(for example 18:00). I wrote program by while loop and incremental index, but it's better to write it with time parameter.

I run mentioned program for 7 hours each day. It must run nonstop.

while(i<500000):
    execute algorithm
    i+=1

But I'd like to run my program like bellow:

while(not 18:00 clock):
    execute algorithm

Solution

  • import datetime
    
    while datetime.datetime.now().hour < 18:
        do stuff...
    

    or

    if datetime.datetime.now().hour >= 18:
        return