gunicorn

使用 supervisor 管理进程

偶尔善良 提交于 2019-12-04 16:25:28
Supervisor ( http://supervisord.org ) 是一个用 Python 写的进程管理工具,可以很方便的用来启动、重启、关闭进程(不仅仅是 Python 进程)。除了对单个进程的控制,还可以同时启动、关闭多个进程,比如很不幸的服务器出问题导致所有应用程序都被杀死,此时可以用 supervisor 同时启动所有应用程序而不是一个一个地敲命令启动。 安装 Supervisor 可以运行在 Linux、Mac OS X 上。如前所述,supervisor 是 Python 编写的,所以安装起来也很方便,可以直接用 pip : sudo pip install supervisor 如果是 Debian / Ubuntu可以直接通过apt安装: # apt-get install supervisor supervisord 配置 Supervisor 相当强大,提供了很丰富的功能,不过我们可能只需要用到其中一小部分。安装完成之后,可以编写配置文件,来满足自己的需求。为了方便,我们把配置分成两部分:supervisord(supervisor 是一个 C/S 模型的程序,这是 server 端,对应的有 client 端:supervisorctl)和应用程序(即我们要管理的程序)。 首先来看 supervisord 的配置文件。安装完 supervisor 之后

Heroku Django Gunicorn 'Foreman Start' error

戏子无情 提交于 2019-12-04 15:50:35
I'm working through the Heroku's Django tutorial and I got all the way down to ' Using a different WSIG server '. When I try to use gunicorn I get the following error: requirements.txt Django==1.4.1 distribute==0.6.28 dj-database-url==0.2.1 psycopg2==2.4.5 gunicorn==0.14.6 Procfile web: gunicorn djtut.wsgi -b 0.0.0.0:$PORT (venv) C:\Users\xxxx\Documents\Python\djtut>foreman check valid procfile detected (web) (venv) C:\Users\xxxx\Documents\Python\djtut>foreman start 10:53:05 web.1 | started with pid 5652 10:53:06 web.1 | exited with code 1 10:53:06 web.1 | Traceback (most recent call last): 10

How does django work with virtualenv?

混江龙づ霸主 提交于 2019-12-04 15:24:00
问题 I understand how to create a virtualenv, activate that virtualenv, and then install django while the virtualenv is activated. Ex: virtualenv ~/narnia source ~/narnia/bin/activate pip install django From what I understand, when you "activate" a virtual environment it just changes some path variables while you're in a shell, nothing more. So when django is installed with pip while narnia is activated, it simply installs things into locations relative to ~/narnia instead of relative to /usr (ex.

Tesseract 3.x multiprocessing weird behaviour

浪尽此生 提交于 2019-12-04 12:28:56
问题 I am not sure whether it is my infrastucture that does this weird stuff or the tesseract-ocr itself. Whenever i use image_to_stirng in single-process environment - the tesseract-ocr works fine. But when I spawn multiple workers with gunicorn and all of them get to do some work with ocr reading - the tesseract-ocr starts reading very poorly (and not from performance-vise, but accuracy-vise). Even after the load is done - tesseract never has the same accuracy. I need to restart all the workers

Gunicorn exits because https request from Django fails in OpenSSL

和自甴很熟 提交于 2019-12-04 12:24:30
Here's the scenario. I have a Django app being served by Gunicorn on Linux. On certain requests it makes an https call to an external API via httplib2.request() . Sometimes that call fails in such a way that hoses OpenSSL (not sure how, but it's not my fault and doesn't really matter). OpenSSL sends a SIGABRT signal to gunicorn in this case. Gunicorn handles the SIGABRT and promptly system exits (as it should). The root issue as I see it is that OpenSSL asynchronously signals the parent process to abort, rather than returning an error code. Don't tell me to abort because of YOUR personal

Gunicorn graceful stopping with docker-compose

跟風遠走 提交于 2019-12-04 12:20:26
I find that when I use docker-compose to shut down my gunicorn (19.7.1) python application, it always takes 10s to shut down. This is the default maximum time docker-compose waits before forcefully killing the process (adjusted with the -t / --timeout parameter). I assume this means that gunicorn isn't being gracefully shut down. I can reproduce this with: docker-compose.yml: version: "3" services: test: build: ./ ports: - 8000:8000 Dockerfile: FROM python RUN pip install gunicorn COPY test.py . EXPOSE 8000 CMD gunicorn -b :8000 test:app test.py def app(_, start_response): """Simplest possible

Nginx: Permission denied to Gunicorn socket on CentOS 7

会有一股神秘感。 提交于 2019-12-04 12:01:56
I'm working in a Django project deployment. I'm working in a CentOS 7 server provided ma EC2 (AWS). I have tried to fix this bug by many ways but I cant understand what am I missing. I'm using ningx and gunicorn to deploy my project. I have created my /etc/systemd/system/myproject.service file with the following content: [Unit] Description=gunicorn daemon After=network.target [Service] User=centos Group=nginx WorkingDirectory=/home/centos/myproject_app ExecStart=/home/centos/myproject_app/django_env/bin/gunicorn --workers 3 --bind unix:/home/centos/myproject_app/django.sock app.wsgi

Python 3 Django on App Engine Standard: App Fails to Start

不问归期 提交于 2019-12-04 09:19:32
I'm trying to deploy a Django application on Google App Engine in the Standard Python37 Environment. I've had a version of it running fine in the Flexible environment, but I'm creating a staging version that I want to run in the Standard env. When I deploy and visit the app I get a 500 error. Looking in the logs I can see some messages about exceptions in worker processes. I get the error: ModuleNotFoundError: No module named 'main' This is the stack trace from the error: Traceback (most recent call last): File "/env/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker

how to run gunicorn on docker

Deadly 提交于 2019-12-04 09:05:03
I have 2 files that depend on each other when docker is start up. 1 is a flask file and one is a file with a few functions. When docker starts, only the functions file will be executed but it imports flask variables from the flask file. Example: Flaskfile import flask from flask import Flask, request import json _flask = Flask(__name__) @_flask.route('/', methods = ['POST']) def flask_main(): s = str(request.form['abc']) ind = global_fn_main(param1,param2,param3) return ind def run(fn_main): global global_fn_main global_fn_main = fn_main _flask.run(debug = False, port = 8080, host = '0.0.0.0',

How to get Gunicorn to use Python 3 instead of Python 2 (502 Bad Gateway)

百般思念 提交于 2019-12-04 07:51:44
问题 I'm trying to get Gunicorn to use Python3 for a Django app I want to make. I'm using Digital Ocean's Django image to get started. It comes with Django, Gunicorn, and Nginx installed and configured. The default Django project that comes with this image seems to work fine for Python 2. I've apt-get 'ed these packages. python3 python3-psycopg2 python3-dev python3-pip In order to try to avoid any problems, I've also done this. pip uninstall django pip3 install django I rm -rf 'ed the stock