0
import schedule 
import time 
def check(num): 
 if num == 1: 
  print('abc'); 
  check(2)
 else: 
  schedule.every(1).minute.do(check, num = 1); 
  while True:
   schedule.run_pending() 
   time.sleep(1); 
check(1);

This is the code i have been using, please suggest

  • use a cron job (on unix) – Chris_Rands Jan 24 '20 at 10:00
  • This is a duplicate of https://stackoverflow.com/questions/373335/how-do-i-get-a-cron-like-scheduler-in-python – Javide Jan 24 '20 at 11:54
  • Does this answer your question? [How do I get a Cron like scheduler in Python?](https://stackoverflow.com/questions/373335/how-do-i-get-a-cron-like-scheduler-in-python) – Javide Jan 24 '20 at 11:55
  • @Javide - Like I mentioned in the comments, i have tried this. And it doesn't work for me for some weird reason. The function runs 10(mins)*60(secs) times for me after the 10mins time is elapsed. It gets into a maximum recursive loop. – Naveen Parashar Jan 24 '20 at 12:17

1 Answers1

0

There are a lot of ways to do this, but this approach is simple:


def function():
#
# your function here
#

while True:
    function()
    time.sleep(5)

Or you can use async to make python not wait for the end of the function to continue

Nathan
  • 3,558
  • 1
  • 18
  • 38
VOLTIS
  • 27
  • 6
  • @Nathan- Using a time.sleep() in a while loop without a scheduler, how does it affect the memory allocation, if the program is made to run for the whole day? Also, time.sleep(), does it make the program stop and restart once the time lapses? – Naveen Parashar Jan 24 '20 at 10:40