我可以像Django一样在Django里运行一些代码 [英] Can I have some code constantly run inside Django like a daemon

查看:180
本文介绍了我可以像Django一样在Django里运行一些代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mod_wsgi通过Apache服务一个django站点。我还有一些Python代码作为后台进程运行(dameon?)。它继续轮询服务器并将数据插入其中一个Django模型。这工作正常,但是我可以将此代码作为我的Django应用程序的一部分,但能够在后台持续运行吗?它不需要是一个进程本身,但Django网站的艺术不断活跃。如果是这样,你能否指出一个例子或一些有助于我完成这些工作的文件?



谢谢。

解决方案

您可以设置一个运行您定义的某些功能的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆