擅长:python、mysql、java
<p>看看<a href="https://docs.python.org/3.4/library/sched.html" rel="nofollow">sched</a>模块。在</p>
<p>下面是一个如何使用它的示例:</p>
<pre><code>import sched, time, datetime
def print_time():
print("The time is now: {}".format(datetime.datetime.now()))
# Run 10 seconds from now
when = time.time() + 10
# Create the scheduler
s = sched.scheduler(time.time)
s.enterabs(when, 1, print_time)
# Run the scheduler
print_time()
print("Executing s.run()")
s.run()
print("s.run() exited")
</code></pre>
<blockquote>
<pre><code>The time is now: 2015-06-04 11:52:11.510234
Executing s.run()
The time is now: 2015-06-04 11:52:21.512534
s.run() exited
</code></pre>
</blockquote>