1

I have a Python script which I want to run using Gunicorn. I have created a wsgi file as I am not using any framework. So I have 3 files in my folder: my Python script (app.py), Wsgi file (wsgi.py), and gunicorn configuration file (gunicorn.config.py). Now please explain how to connect all these files using gunicorn configuration file. I am using below command to run gunicorn:

gunicorn -c gunicorn.conf.py --pid gunicorn.pid wsgi:application

wsgi is the file and application is the function which accepts two positional parameters: A dictionary containing CGI like variables; and a callback function that will be used by the application to send HTTP status code/message and HTTP headers to the server. This function returns the response body to the server as strings wrapped in an iterable.

I have imported my main function from my Python script which needs to be run from the app.py file in gunicorn config file. Also below is my wsgi file code:

import os
from app import application

# Set environment variables
os.environ['DB_USER'] = ''
os.environ['DB_PASSWORD'] = ''
os.environ['DB_HOST'] = ''
os.environ['DB_NAME'] = ''
os.environ['DB_PORT'] = ''  
# The WSGI application callable
app = application`

application is a function defined in the app.py file which is calling my main function which is in the same file. But using this process there is no error while running Gunicorn but I am not getting my output.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.