本文介绍了如何运行django的"python manage.py runserver",celery的"celery -A app_name worker -l info";和redis-server在一个命令中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用django.我开始做一个小项目.我一直在用芹菜和Redis工人.每次使用celery和redis时,我必须先运行celery和redis服务器,然后再运行django服务器.这是一个漫长的过程.我有两个问题.1.我是否通过每次运行服务器来做正确的事情,或者此过程还有其他正确的方法吗?2.如果我的方向正确,是否有任何方法可以做到这一点?

我尝试了circus.ini,但没有用.

解决方案

如果使用UNIX系统:

  1. 为此,您可以与 bash 融洽相处.只需在后台运行 celery redis -使用& 命令即可.
  redis-server&芹菜-app_name工人-l信息&python manage.py运行服务器 

此方法的缺点-即使关闭 django开发服务器 redis celery 仍将在后台运行.因此,您需要终止这些过程.有关如何执行此操作的示例,请参见此Unix答案.

因此,您可以创建2个bash脚本 start.sh (包含带有& 的命令)和 cleanup.sh (终止进程),以及分别运行它们.

有关生产的信息,请参见目的2

  1. 使用 systemd supervisor .您需要为守护程序创建conf文件,然后运行它们.

I have recently started with django. And I started doing a small project. I've been using celery with redis worker. And every to use celery and redis I have to run the celery and redis server and then django server. Which is a bit lengthy process. I have two questions.1. Am I doing the right thing by running the servers everytime or are there any other right method to this process?2. If I'm in the right direction, is there any method to do this?

I tried circus.ini , but it did not work.

解决方案

If you use UNIX system:

  1. For this purpose you can get along just with bash. Just run celery and redis in background - use & command.
redis-server & celery -A app_name worker -l info & python manage.py runserver

Disadvantage of this approach - redis and celery will work in the background even after a shutdown of django dev server. So you need to terminate these processes. See this unix se answer for examples how to do that.

So you can create 2 bash scripts start.sh (contains commands with &) and cleanup.sh (terminate processes) and run them respectively.

For production see purpose #2

  1. Use systemd or supervisor. You need to create conf files for your daemons and then run them.

这篇关于如何运行django的"python manage.py runserver",celery的"celery -A app_name worker -l info";和redis-server在一个命令中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 19:37