擅长:python、mysql、java
<p>我也遇到了同样的问题,于是推迟了用芹菜(太复杂)或cron(应用程序外部)来解决它的尝试,最终找到了<a href="http://packages.python.org/APScheduler/index.html">Advanced Python Scheduler</a>。只是刚刚开始使用它,但它看起来相当成熟和稳定,有像样的文档,并将采取多种调度格式(例如cron样式)。</p>
<p>从<a href="http://packages.python.org/APScheduler/intervalschedule.html">documentation</a>,以特定间隔运行函数。</p>
<pre><code>from apscheduler.scheduler import Scheduler
sched = Scheduler()
sched.start()
def hello_world():
print "hello world"
sched.add_interval_job(hello_world,seconds=10)
</code></pre>
<p>这是非阻塞的,我只需从我的<code>urls.py</code>中导入模块就可以运行完全相同的程序。希望这有帮助。</p>