-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve documentation on running gunicorn from Python with custom applications #1429
Comments
maybe @matrixise can help there since he's supposed to maintain that feature? |
For 1), perhaps we can provide a factory function that returns an application class? We can use 2) as an opportunity to refactor the API (if needed) and document it. |
@duffsterlp out of curiosity, what's the reaon to not simply use the gunicorn command line? |
For example, you have a CLI which you need to pass some parameters to in order to start the server. |
Bringing this back from the dead, I've been on a bit of a witch hunt, and I think this would solve my issue. Context: We're a microservice type company, and we have virtual machines that act as containers, but container management software can't be adopted in full at $work yet. To cut a huge amount of complexity from $configmanager and $deployer, we're taking the PEX deployable route for python web services, and these apps generally exist as Flask services around here, though Django would be a nice to have. Unfortunately, PEX is... difficult... to deal with in wsgi-land. You can't set up wsgi to serve a PEX, or add a PEX to a path, or any of the normal pythonic goodness, but given that Gunicorn is in python, it seems to stand to reason that one could instantiate a Flask app and pass that to Gunicorn in a python context. As PEX is just an executable zip file, it requires a single entry point that should take over and run the application - and it seems like a reasonable thing to set up gunicorn within a PEX file, but I'm not seeing any information on writing an entry point script that extends Gunicorn and runs a Flask application (or other wsgi compatible app that isn't totally homebrewed). All that outta the way - is there information on writing a python script that effectively runs Gunicorn(FlaskApp)? Perhaps someone here has a gist or other example of how to boilerplate this?
|
Nevermind that last question, I still think it warrants a bit more TLC to the docs regarding running wsgi-compatible apps from a pure python context but I made a bit of headway and can move forward. Perhaps I spent too long reading in circles around it, but I never found it in the docs that I could use this as a 'run.py':
...which then can be used like "run.py flaskOrWhatev:entry_point". Pertaining to PEX, in case anyone comes across this, you can set the entry point to the PEX file as 'run' in this example, compile the PEX, and run 'myapp.pex flaskOrWhatev:entry_point' - plus any other appropriate cmd options - and it works like a portable gunicorn charm. I had to search the source repo for use of "APP_MODULE" to figure this out though 😐 Assuming that's an appropriate usage of the WSGIApplication class, is there somewhere in particular that bit of information might fit best in the docs? I'd be happy to PR it. Also, is it worth creating an issue for optionally setting APP_MODULE via env variable or config file, or would that not be considered for implementation for some reason? |
@jakethedev I also ran into this with pex files. Your solution was everything I needed! Thanks for posting this. |
Glad it helped!
and pass your app identifier ( |
Well, I haven't felt this dumb since calculus, but I've learned quite a bit since this last comment... To everyone who cares - you literally just run Once gunicorn is installed as a dep or on the system, the entry_points it declares in setup.py install the CLI shortcut Anyways. Hope this clears things up for anyone that hits this thread and maybe hasn't done significant work with setup.py files, or is building out python support in their CI with no python dev knowledge like I am 😅 |
closing as answered. thanks for the thread and PR. |
I'm running gunicorn using the falcon web framework and would like to run gunicorn from the Python interpreter directly, similar to this issue here:
#91
I now know how to accomplish this from a combination of these links as well as a conversation in the IRC room.
http://docs.gunicorn.org/en/stable/custom.html
https://gist.github.com/quamilek/4fd1f246feb6149dd1dd/
The latter link really shed light that the "Custom Application" section of the documentation was the appropriate place to connect Gunicorn with existing WSGI frameworks. The Gunicorn documentation alone did not provide ample indication of this, in my opinion.
I'm looking for the following improvements in the Custom Application page:
The text was updated successfully, but these errors were encountered: