我可以像Django一样在Django里运行一些代码 [英] Can I have some code constantly run inside Django like a daemon
问题描述
谢谢。
您可以设置一个运行您定义的某些功能的cron作业,或者 - 更先进和可能推荐的方法,集成芹菜(实际上很简单)。
I'm using mod_wsgi to serve a django site through Apache. I also have some Python code that runs as a background process (dameon?). It keeps polling a server and inserts data into one of the Django models. This works fine but can I have this code be a part of my Django application and yet able to constantly run in the background? It doesn't need to be a process per se but a art of the Django site that is active constantly. If so, could you point me to an example or some documentation that would help me accomplish this?
Thanks.
You could either set up a cron job that runs some function you have defined, or - the more advanced and probably recommended method, integrate celery in your project (which is quite easy, actually).
这篇关于我可以像Django一样在Django里运行一些代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!