I use this command in docker compose:
newrelic-admin run-program gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000
but after running, I encountered with following error:
(14/ThreadPoolExecutor-0_0) newrelic.core.trace_cache ERROR - Runtime instrumentation error. An active trace already exists in the cache on thread_id 281472746332640. Report this issue to New Relic support.
How can I fix it?!
Thanks
I initialized newrelic.ini config in main.py. It works and the errors were fixed:
import newrelic.agent
newrelic.agent.initialize('newrelic.ini')
Related
I followed github/stackoverflow resources, watched youtube videos, read heroku official docs but in the end, I still getting error (network erro). Can someone help me what is the problem going on with my project?
I upoloaded project in github and linked with heroku. Used environment variable as heroku config vars with database strings, projects with project secret keys etc.
My requirements.txt file below
appdirs
typing
dnspython
email-validator
fastapi
motor
datetime
jose
passlib
dataclasses
typing-extensions
pydantic
starlette
uvicorn
bson
gunicorn
h11
click
pylint
astroid
websockets
In Procfile I wrote this in each different commits
web: gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app
and then this
web: uvicorn main:app --host=0.0.0.0 --port=${PORT:-5000}
and this
web: uvicorn main:app --host="0.0.0.0" --port=${PORT:-8000}
and also
web: uvicorn main:app --host "0.0.0.0" --port ${PORT}
but none of them are workable.
and also updated runtime.txt file several time with different python versions.
May be I tried every possibilities from internet but what is the god damn problem ?
You must check the logs by running this command from your terminal.
"heroku logs --tail -a [applicationname]".
In my case the issue is this "pip install "pymongo[srv]" which I found from the logs. In the solution is to add this "dnspython==2.1.0" in the requirements.txt and redeploy.
I trying to deploy my app on GAE using their trial version. I was so far successful in creating an app.yaml with a custom settings for flexible environment with python 3.6.
However, while deploying the app, the app builds successfully, however, I keep getting the following error
Updating service [default] (this may take several minutes)...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
/bin/sh: 1: exec: gunicorn: not found
Following is the folder hierarchy of files in my project:
Following the code for app.yaml
env: flex
runtime: custom
api_version: 1
entrypoint: gunicorn -b :$PORT main:app
runtime_config:
python_version: 3.6
#handlers:
#- url: /SmsResponse
# script: Twilio_Routing.RecivedSms
#
#- url: /CallResponse
# script: Twilio_Routing.ReceivedCall
I am surely missing out on something and I would really appreciate some help here.
Link to git repo
requirements.txt
Flask==0.10.1
gunicorn==19.3.0
twilio==6.8.4
DockerFile
FROM gcr.io/google-appengine/python
LABEL python_version=python3.6
RUN virtualenv --no-download /env -p python3.6
# Set virtualenv environment variables. This is equivalent to running
# source /env/bin/activate
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH
# Copy the application's requirements.txt and run pip to install all
# dependencies into the virtualenv.
ADD requirements.txt requirements.txt
RUN pip install -r requirements.txt
ADD . /app/
#CMD gunicorn -b :$PORT main:app
ENTRYPOINT [ "python", "Twilio_Routing.py" ]
P.S. After the changes for the requirements.txt, I am getting error 502 Bad Gateway.
Logs showing that the service was executed successfully.
017-12-25 01:29:03 default[20171224t212610] * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
2017-12-25 01:29:03 default[20171224t212610] * Restarting with stat
2017-12-25 01:29:03 default[20171224t212610] * Debugger is active!
2017-12-25 01:29:03 default[20171224t212610] * Debugger PIN: 134-103-452
2017-12-25 01:29:17 default[20171224t212610] * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
2017-12-25 01:29:17 default[20171224t212610] * Restarting with stat
2017-12-25 01:29:17 default[20171224t212610] * Debugger is active!
2017-12-25 01:29:17 default[20171224t212610] * Debugger PIN: 134-103-452
Can someone look at my code in git and tell me what is it that I am missing here?
for me the error was as simple as making sure gunicorn was in requirements.txt
Flask==1.0.2
gunicorn==19.9.0
Note:
I see the OP had added this flag; this is to help others that may be running into exec: gunicorn: not found
A few changes and I was able to run your app in docker.
In Twilio_Routing.py , change host to listen on 0.0.0.0 instead of 127.0.0.1.This is needed to to have the server available externally as well.
Since your app.yaml is already configured, you don't need to customize your Dockerfile as Google App Engine requires. Keep it as your own custom one.Here's what I used:
#Python's Alpine Base Image
FROM python:3.6-alpine3.6
#Installing all python modules specified
ADD requirements.txt requirements.txt
RUN pip install -r requirements.txt
#Copy App Contents
ADD . /app
WORKDIR /app
#Start Flask Server
CMD [ "python","Twilio_Routing.py"]
#Expose server port
EXPOSE 8080
Considering the example shown in the GoogleCloudPlatform/python-runtime page, consider changing your CMD line from:
CMD exec gunicorn -b :$PORT main:app
To:
CMD gunicorn -b :$PORT main:app
I see exec used here only when the base image is the python one, not gcr.io/google-appengine/python.
I also came across this error recently when I tried to run my docker image.
/bin/sh: 1: gunicorn: not found
Simple trick that worked for me
delete the container and the image
restart the docker engine.
and try to create the image again using the below commands
docker build -t <image_name>:<tag_name> .
and try to run using this command.
docker run -p 5000:5000 -e PORT =5000 image id
it worked for me! hope it helps.
I'm trying to host flask API which is using tensorflow libraries.I installed tensorflow gpu library with CUDA and cudnn libraries.I manually checked with the following command which is working fine.
/captcha/env/bin/gunicorn captcha:app -b 0.0.0.0:5124 -k gevent --worker-connections 1000
But when i add this systemd service im getting a tensorflow gpu error
systemd service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
PIDFile=/run/gunicorn/pid
User=root
Group=root
WorkingDirectory=/captcha/env
ExecStart=/captcha/env/bin/gunicorn captcha:app -b 0.0.0.0:5124 -k gevent --worker-connections 1000
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Error text in Log file:
Failed to load the native TensorFlow runtime.
See
https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
Can anyone point me where I'm doing wrong?
Systemd seems to strip all the environment variables and TensorFlow needs to know where to find Cuda. Without a LD_LIBRARY_PATH it fails.
There are probably a handful of ways to do this, but this worked for me.
[Service]
Environment=LD_LIBRARY_PATH=/usr/local/cuda/lib64
ExecStart=/path/to/your/app
...
I'm using PM2 to manage tensorflow-flask api process.
http://pm2.keymetrics.io/
I Create a shell file with the following command as a content.
pm2 start run.sh
I am trying to run a aiohttp based server using Gunicorn.
Here is the command:
gunicorn aiohttpdemo_polls:app --bind 127.0.0.1:8080
It returns:
Failed to find application: 'aiohttpdemo_polls'
But when I am running it using python -m like below:
python -m aiohttpdemo_polls
It works fine. The code can be found from here which is a demo app in the aiohttp repo.
Also tried it like below:
gunicorn aiohttpdemo_polls.main:app --bind 127.0.0.1:8080
But its also not running the server. It returns
Failed to find application: 'aiohttpdemo_polls.main'
Any idea where to look further for fixing the issue?
aiohttp 3.1 supports coroutine as application factory, such as:
async def my_web_app():
app = web.Application()
app.router.add_get('/', index)
return app
Current implementation of aiohttpdemo_polls uses this approach. It can be started with
gunicorn aiohttpdemo_polls.main:init_app --bind localhost:8080 --worker-class aiohttp.GunicornWebWorker
The demo does not support gunicorn yet.
I filed an issue: https://github.com/aio-libs/aiohttp-demos/issues/10
Thanks for report.
I have a simple flask script that uses requests to make http requests to third party web service. The way I run the script in gunicorn is
gunicorn abc:APP -b 0.0.0.0:8080 -w 4 -k gevent --timeout 30 --preload
However, after I upgrade the code to python 3.6.2, I can still run the server, but whenever the webserver received a request, it shows
RecursionError: maximum recursion depth exceeded while calling a Python object
on every worker, and the server seems are still running. When I change the running command to
gunicorn abc:APP -b 0.0.0.0:8080 -w 4 --timeout 30 --preload
It all works again. So is there any issue with gunicorn's async worker and requests in python 3.6.2? Is there a way to fix this?
(This question is also asked at https://github.com/benoitc/gunicorn/issues/1559)
This is because of the ssl is imported before monkey patch, gunicorn import the ssl module(config.py in gevent) when loading config,however the monkey patch is called when init the worker or at the top of app.py file which is definitely after import of ssl, this is why we get the warning.
A simple solution is to use a config file for gunicorn.
we could do gevent monkey patch at the beginning of config file, and start gunicorn with the config file, in this way, the monkey patch could be completed before import ssl, and thus avoid this problem.
A config file named gunicorn_config.py could contain lines below:
import gevent.monkey
gevent.monkey.patch_all()
workers = 8
and then we could start gunicorn with
gunicorn --config config.py --worker-class gevent --preload -b 0.0.0.0:5000 app:app
More information could be found here
Please see https://github.com/benoitc/gunicorn/issues/1559. This may possibly be fixed in the next version of gunicorn, but unfortunately you may have to stay with python 3.5.2 if you don't want to break gunicorn.