mardi 31 décembre 2019

Python - schedule with random delay

I'am learning python by doing little projects on my own. I'am struggling to schedule scripts with random delay in a range. In the code below, the delay is random but always the same ... I Really need help.

import schedule
import time
import random
import datetime


def job():
    t = datetime.datetime.now().replace(microsecond=0)
    print(str(t) + "  hello")


i = 0
while i < 10:
    delay = random.randrange(1, 5)
    schedule.every(delay).seconds.do(job)
    i += 1

    while True:
        schedule.run_pending()
        time.sleep(1)







Aucun commentaire:

Enregistrer un commentaire