0

I want to know how can execute a written function automatically after a given time for specified seconds.

for example i want to run function 10 seconds after executing program for 5 seconds.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Omid Goudazi
  • 120
  • 2
  • 9

3 Answers3

2

In python 2.7 you can use the sleep method. See here: http://docs.python.org/2/library/time.html#time.sleep

0

You can look at apscheduler. Ir allows you to run scheduled repetitive tasks

http://pythonhosted.org/APScheduler/

Ranjith Ramachandra
  • 10,399
  • 14
  • 59
  • 96
0

You can sleep for 5 seconds, then execute a determined functionB. But you can't assure to run the functionB for a determined number of seconds unless you sleep it too. For example:

import time

def funcA():
    secs = 5
    time.sleep(secs)  # Sleep 5 seconds
    funcB()

def funcB():
    secs = 10
    time.sleep(secs)  # Sleep 10 seconds

You can also make this in a thread.

dablak
  • 1,376
  • 1
  • 11
  • 21