Does anyone know if package install order matters in Python? More specifically my pip requirements.txt for a Django website I am building was:
Django==1.4
MySQL-python==1.2.3
django-evolution==0.6.7
django-pagination==1.0.7
boto==2.5.2
numpy==1.6.2
requests==0.13.1
simplejson==2.5.2
gunicorn==0.14.6
When deploying to Heroku the application would crash with the following error:
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [12] [INFO] Worker exiting (pid: 12)
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [8] [INFO] Worker exiting (pid: 8)
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [4] [INFO] Handling signal: term
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [7] [INFO] Worker exiting (pid: 7)
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [4] [INFO] Starting gunicorn 0.14.6
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [4] [INFO] Listening at: http://0.0.0.0:20132 (4)
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [4] [INFO] Using worker: sync
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [7] [INFO] Booting worker with pid: 7
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [8] [INFO] Booting worker with pid: 8
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [9] [INFO] Booting worker with pid: 9
2012-08-05T09:26:56+00:00 app[web.1]: 2012-08-05 09:26:56 [10] [INFO] Booting worker with pid: 10
2012-08-05T09:26:57+00:00 heroku[web.1]: State changed from starting to up
2012-08-05T09:26:57+00:00 heroku[web.1]: Process exited with status 143
2012-08-05T09:27:17+00:00 app[web.1]: Usage: gunicorn [options]
2012-08-05T09:27:17+00:00 app[web.1]: gunicorn: error: no such option: --workers
2012-08-05T09:27:17+00:00 app[web.1]:
2012-08-05T09:27:17+00:00 app[web.1]: 2012-08-05 09:27:17 [9] [INFO] Worker exiting (pid: 9)
Where my Procfile is as follows:
web: python manage.py collectstatic --noinput; gunicorn commerical_production.wsgi:application --workers=4 --bind=0.0.0.0:$PORT
The problem was fixed by simply changing the order of requirements to:
Django==1.4
gunicorn==0.14.6
MySQL-python==1.2.3
django-evolution==0.6.7
django-pagination==1.0.7
boto==2.5.2
numpy==1.6.2
requests==0.13.1
simplejson==2.5.2
(note that gunicorn is now moved to the top)
I found this out by luckily guessing to try and change the order of the imports but my question is has anyone else run into this problem or know why the order of the packages makes a difference when installed from the requirements.txt? Could this problem indicative of some larger dependency issue that is in my app?
Pip is not very good at handling package dependencies as easy_install. We had the same problem in our project. Even though the order in req.txt was correct, we had dependency problems that is related to order.
My solution is to feed the req.txt to easy_install, but than you should be careful with the packages that is editable or those from github etc.
You may want to check below links:
http://metak4ml.blogspot.com/2009/08/easyinstall-read-pip-requirementstxt.html
http://community.webfaction.com/questions/1220/using-easy_install-to-get-all-dependencies-listed-in-requirementstxt (while read line answer is close to what we do)
Pyton setup install scripts hold already requirements and order, so the install process will respect and install in order all requirements for each of your app in the requirements file.
So, if you have your own applications that require others, put your requirements only in your setup files and enroll your main application in the requirements.txt
For third party python apps that don't require compilation you don't have to worry about the order in your requirements.
Otherwise eazy_install becomes deprecated, use pip instead of it.
Related
starting process with command from procfile works.
then as soon as it starts reading the python file, and pulling data from an API, we get
[2020-03-23 17:48:55 +0000] [10] [ERROR] Exception in worker process
Which traces down to
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 409: Conflict
And then
[2020-03-23 17:48:55 +0000] [10] [INFO] Worker exiting (pid: 10)
Before it looks like its successfully calling the API on a second attempt and then ultimately
[2020-03-23 17:49:03 +0000] [11] [INFO] Worker exiting (pid: 11)
[2020-03-23 17:49:04 +0000] [4] [INFO] Shutting down: Master
[2020-03-23 17:49:04 +0000] [4] [INFO] Reason: Worker failed to boot.
And it crashes, exiting with status 3.
How do I solve this 409 error? Is there some environment variable or something that has to be set in the python app before deploying to Heroku? The app works locally (i.e. API calls work), just when trying to put on a server do I encounter this.
I'm using :
python 3.6
django==2.1.1
gunicorn==19.9.0
i have done the following:
created a django project called api
created an apiapp (an app in my project)
and i have this code in api_app's apps.py :
from django.apps import AppConfig
from api import settings
class ApiappConfig(AppConfig):
name = 'apiapp'
verbose_name = "random_name"
def ready(self):
self.job()
#classmethod
def job(cls):
### doing whatever here for example :
print(settings.SHARED_VARIABLE)
and the following in api_app's __init__.py:
import os
default_app_config = 'apiapp.apps.ApiappConfig'
i'm creating an API so i am required to use multiple workers when deploying:
gunicorn api.wsgi -w 10
now, my issue is that the function job which is called when the server is started, is getting called 10 times because i'm using 10 gunicorn workers, i would like to call it only once
another thing that i would like to do is to have the
settings.SHARED_VARIABLE variable, shared between the different workers. this variable will be updated only by the worker that will launch the app.py on server start.
Thank you !
gunicorn has a setting to do this: --preload
So, after I add this in settings.py: SHARED_VARIABLE = 'content of SHARED_VARIABLE' (and fixed apiapp/__init__.py to use the real app name), I can run gunicorn with the application loaded only once:
$ gunicorn api.wsgi -w 10 --preload
content of SHARED_VARIABLE
[2018-12-31 10:12:15 +0000] [394] [INFO] Starting gunicorn 19.6.0
[2018-12-31 10:12:15 +0000] [394] [INFO] Listening at: http://127.0.0.1:8000 (394)
[2018-12-31 10:12:15 +0000] [394] [INFO] Using worker: sync
[2018-12-31 10:12:15 +0000] [399] [INFO] Booting worker with pid: 399
[2018-12-31 10:12:15 +0000] [400] [INFO] Booting worker with pid: 400
[2018-12-31 10:12:15 +0000] [401] [INFO] Booting worker with pid: 401
[2018-12-31 10:12:15 +0000] [403] [INFO] Booting worker with pid: 403
[2018-12-31 10:12:15 +0000] [404] [INFO] Booting worker with pid: 404
[2018-12-31 10:12:15 +0000] [405] [INFO] Booting worker with pid: 405
[2018-12-31 10:12:15 +0000] [406] [INFO] Booting worker with pid: 406
[2018-12-31 10:12:15 +0000] [408] [INFO] Booting worker with pid: 408
[2018-12-31 10:12:15 +0000] [410] [INFO] Booting worker with pid: 410
[2018-12-31 10:12:15 +0000] [411] [INFO] Booting worker with pid: 411
When I start gunicorn it prints this:
[2018-11-09 16:30:20 +0000] [16] [INFO] Starting gunicorn 19.9.0
[2018-11-09 16:30:20 +0000] [16] [INFO] Listening at: http://0.0.0.0:8000 (16)
[2018-11-09 16:30:20 +0000] [16] [INFO] Using worker: sync
[2018-11-09 16:30:20 +0000] [19] [INFO] Booting worker with pid: 19
Setting up a logger for the gunicorn package (propagating) doesn't seem to affect it. What module is the one I should configure to modify these messages?
Those messages are output by the Arbiter class in gunicorn/arbiter.py, but it may be that any configuring you try and do is overridden by gunicorn's machinery, or not applicable - for example, trying to set up logging in a worker won't affect what the arbiter does, as they are separate processes. So you may need to invoke the arbiter in a special way (i.e. not just through running a canned gunicorn script) if you want to affect its logging, or amend the gunicorn configuration used for the arbiter.
I am trying to deploy my app using Google App Engine. I have edited app.yaml to reflect the flexible environment and also gave all the app information. Below is the app.yaml file.
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app
runtime_config:
python_version: 3
Once the deployment is in progress, I am getting the following error
[2018-08-24 06:57:14 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2018-08-24 06:57:14 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2018-08-24 06:57:14 +0000] [1] [INFO] Using worker: sync
[2018-08-24 06:57:14 +0000] [7] [INFO] Booting worker with pid: 7
App Deployed
Failed to find application: 'main'
[2018-08-24 06:57:14 +0000] [7] [INFO] Worker exiting (pid: 7)
[2018-08-24 06:57:14 +0000] [1] [INFO] Shutting down: Master
[2018-08-24 06:57:14 +0000] [1] [INFO] Reason: App failed to load.
Please note that App Deployed is the line in my print statement. It is getting executed. But the deployment is getting failed
Thank you in advance
In your app.yaml, you're starting gunicorn with gunicorn -b :$PORT main:app. This tells it to look for the object app in the file main.py
The error you're getting comes from gunicorn and occurs when you have a main.py file, but it does not have an app object in it.
You probably want to set up a Flask app as follows:
from flask import Flask
app = Flask(__name__)
See a full example app here: https://cloud.google.com/appengine/docs/flexible/python/quickstart#hello_world_code_review
I have had the same issue.
Failed to find application: 'main'
The reason in my case was that I had a directory called also main in the root project directory.
drwxr-xr-x 2 user staff 64 Nov 30 10:12 main
-rw-r--r-- 1 user staff 1178 Nov 29 20:58 main.py
I guess gunicorn got confused.
The solution (worked for me): to rename main directory.
P.S. Just don't rename it to code directory. It will cause another issue with debugging in PyCharm. :)
My folder structure is looks llike this the main.py is not in the root directory how I can specify this in app.yaml file.
/app
|__main.py
app.yaml
I'm trying to setup new relic, I have followed the instructions they give however the last command give me this error.
newrelic-admin run-program gunicorn wsgi:application
why?
2013-04-16 10:39:30 [4175] [INFO] Starting gunicorn 0.14.5
2013-04-16 10:39:30 [4175] [INFO] Listening at: http://127.0.0.1:8000 (4175)
2013-04-16 10:39:30 [4175] [INFO] Using worker: sync
2013-04-16 10:39:30 [4178] [INFO] Booting worker with pid: 4178
2013-04-16 10:39:30 [4178] [INFO] Worker exiting (pid: 4178)
2013-04-16 10:39:31 [4175] [INFO] Shutting down: Master
2013-04-16 10:39:31 [4175] [INFO] Reason: Worker failed to boot.
Follow the instructions found here:
https://newrelic.com/docs/python/python-agent-integration
I'm assuming as this i posted in Django that its a Django app.
add
import newrelic.agent
newrelic.agent.initialize('/some/path/newrelic.ini')