我正在尝试使用 screen 命令在 aws ec2 实例(ubuntu)上运行 django 服务器。
screen -L python3 manage.py runserver 0.0.0.0:8000
我的脚本以简单的通用方式工作,它检测 POST 请求,通过 HttpResponse 处理和响应。
我的代码在views.py 中看起来有点像这样。
def myResponse(arg):
"""
processing here
"""
#this function gets executed
#code below does not get executed, it gets cut off when, new request comes
HttpResponse("responseString")
def index(request):
if (request.method == "POST"):
"""
process here
"""
#this function gets triggered, whenever post request is detected
myResponse(arg)
HttpResponse("anotheresponseString")
当一个用户正在交互时,突然有新用户迭代并检测到新的发布请求,旧的流程就会被切断。没有错误被抛出。
如何处理多个用户?
最佳答案
使用 Gunicorn 或 Celery 运行 django 服务器并处理您的请求。
unicorn
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/gunicorn/
celery
https://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
关于django 服务器(托管在 ec2 ubuntu 上)对多个用户失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58542187/