call function every 5 seconds using python and schedule

Free Python Code - Aug 14 '23 - - Dev Community

welcome everybody 🙂🖐

Today I will share with you how to call function every 5 seconds using python and schedule

step 1

install schedule from here : pip install schedule

step 2


import schedule

def task():
    print('this is task ;)')

schedule.every(5).seconds.do(task)

while True:
    schedule.run_pending()

Enter fullscreen mode Exit fullscreen mode

you can pass arguments to task function


import schedule


def task(name):
    print(f'this is {name} task ;)')

schedule.every(5).seconds.do(task, name = 'create app')

while True:
    schedule.run_pending()

Enter fullscreen mode Exit fullscreen mode

Now we're done 🤗

Don't forget to like and follow 🙂

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .