One, when you want a method to be executed after a few seconds or even longer, you can do this:
Import time
from threading import Timer
def print_time (enter_time):
print ' Now ', Time.time (), enter_the _box_time is ", Enter_time
print time.time ()
timer (5, Print_time, (Time.time (),)). Start ()
timer (10, Print_time, (Time.time (),)). Start ()
print time.time ()
In this case, the Print_time method is executed once from the program to 5, second, and 10 seconds.
Second, when you want to let one of your methods to perform in a certain period of time, this requires the framework of the timing task Apscheduler, the introduction of the online installation of Apscheduler is simple:
Easy_install Apscheduler on the line, unfortunately I might use the reason for Python 2.7, although the installation was prompted to succeed, but write code to introduce these packages always have problems, and finally
I found a apscheduler2.0 software package, unpack and switch to the corresponding directory after the Python setup.py install to solve the problem, this package in my resources can be downloaded.
Then you can start writing code, the code implementation style has two:
1, with the modifier of the wording:
From Apscheduler.scheduler Import Scheduler
import datetime
Schedudler = Scheduler (Daemonic = False)
@ Schedudler.cron_schedule (second= ', day_of_week= ' 0-7 ', hour= ' 9-12,13-16 ')
def quote_send_sh_job ():
print ' A simple cron job start at ', Datetime.datetime.now ()
Schedudler.start ()
2, without the modifier of the wording:
def cornstart (self,event):
Schedudler = Scheduler (Daemonic = True)
schedudler.add_cron_job (Self.timing_exe, day_of_week= ' Mon-sun ', hour= ' 0-12 ', minute= ' 0-59 ', second= ', '
print ' get start '
Schedudler.start ()
The
should be well understood, Timing_exe is the name of the function to execute, and if the function has parameters that can be added to a args[]