Does Gunicorn run on Windows - python

I have looked around for a while, and I was surprised not finding any information whether Gunicorn runs on Windows or not.
Does anyone know if that is the case, and if so, where can I find some documentation about it?

Technically this is not an answer. But practically the answer I was looking for is how to run a WSGI web app (like Django) on Windows, and for those who got into this page because of that, here it is:
I'm using waitress now, very good alternative :)
Basically all you have to do is replace the gunicorn call with:
waitress-serve --listen=*:8000 myapp.wsgi:application
For typical apps this will give you the same result as running gunicorn. :) Good luck!

Gunicorn is for a UNIX environment and is incompatible with Windows.
Also for more info please refer to it's docs.

Edit: there's now a plan to add Windows support. https://github.com/benoitc/gunicorn/issues/524
No. Gunicorn doesn't run on Windows. It's very design is to take 'advantage of features in Unix/Unix-like kernels'.

gunicorn used not to run directly on Windows, but work (and pending issues being resolved) mean that you can make it work on Cygwin.
See https://github.com/benoitc/gunicorn/issues/407 ....
(Note: I update this answer because the bug has now been fixed)

Gunicorn does not support windows, although you can use waitress

I'm trying to Build ASGI app on windows using FASTAPI. FASTAPI is run on Gunicorn & Uvicorn server.I read the FASTAPI documentation to find out how to deploy my app on windows. They suggesting to use docker to deploy the app from windows. It turns out to be the best way to use Gunicorn on windows.

On Windows, you can install guvicorn like that:
pip install uvicorn gunicorn
And then, run your server using the notation available in https://www.uvicorn.org/. Example:
uvicorn myproject.asgi:application --host 127.0.0.1 --port 80 --reload
It's how I use in production and it's being consistent to serve my Django ASGI applications.

Related

python flask code - on windows through HTTP request

I have come with python flask code which uses python libraries pywin32 and pYAD. I need to run these in production enviornment.
I tried to enable it over IIS through wfastcgi but its not working as expected.
Is there a way I can leverage the script to use in production set up, I have tried using Always Up converting script as a service but its not allowed in my organization similar with NSSM.
Is there any other way to explore this. Kindly help
Thanks
You can try waitress. You'll find the documentation Here.
Install Waitress
pip install waitress
setup.py file
from waitress import serve
import main
serve(main.app, host='0.0.0.0', port=8080) #'main.app' being your entry point
run setup.py and access your app through http://host_ip_address:8080

Can't find web process procfile error with Windows Heroku

I want to deploy my website which works locally, but runs an error when it tries to have a public instance.
I am on Windows 8.1 and following the official instructions have created a Procfile.windows. It looks like this:
web: python app.py runserver 0.0.0.0:5000
The build works, but then I get this error when I run heroku ps:scale web=1:
Couldn't find that process type (web).
Repo here.
The official tutorial works, so there's definitely proof of concept of this working somehow.
I am on Windows 8.1 and following the official instructions have created a Procfile.windows
Why did you name this file Procfile.windows? The documentation is quite clear:
The Procfile is always a simple text file that is named Procfile without a file extension. For example, Procfile.txt is not valid.
Rename it to Procfile and redeploy.
Once you've got that working, install a WSGI server and use that instead of manage.py runserver, which isn't suitable for production use:
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that’s how it’s gonna stay. We’re in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)
Gunicorn is probably the most common choice, but I don't think it works on Windows so you won't be able to use it in your development environment. uWSGI or Waitress should work.
I installed Waitress and changed my Procfile to
web: waitress-serve --port=$PORT app:app
I also removed the .windows extension, which is meant for local development.
It works fine now!
(My equivalent to "main.py" was "app.py" so you'd likely change this for your needs to {main.py}:app)
Edit your procfile to look like
web: gunicorn --bind 0.0.0.0:$PORT app:app
And your procfile.windows filed as
web: python app.py runserver 0.0.0.0:5000

Run Django with python as daemon

We have web application which is running with django, python and PostgreSQL. We are also using virtualenv.
To start the web service, we first activate the virtualenv and then start python as service on 8080 with nohup.
But after sometime nohup process dies. Is there any way to launch service as demon like apache, or use some thing like monit?
I am new to this, please excuse my mistakes
So a runserver command should only be used in testing environments. And just like #Alasdair said, Django docs already have interesting information about that topic.
I would suggest using gunicorn as a wsgi with nginx as a reverse proxy. You can find more information here
And i would suggest using supervisor to monitor and control your gunicorn workers. More information can be found here
It may be a good idea to deploy your application using apache or ngnix. There is official Django documentation on how to do it with apache - https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/modwsgi/
Apache does support virtual environment - just add python-home=<path_to_your_virtual_env> to the WSGIDaemonProcess directive when using daemon mode of mod_wsgi:
WSGIDaemonProcess django python-path=/opt/portal/src/ python-home=/opt/venv/django home=/opt/portal/
Best practice for how to use mod_wsgi and virtual environments is explained in:
http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html
I was able to do it, but forgot to update the answers.IF any one is looking for same they can follow this.
Best way to run django app in production is to run with
django+gunicorn+supervisor+nginx.
I used gunicorn which is a Python WSGI HTTP Server for UNIX where you can control thread count, timeout settings and much more. gunicorn was running was on socket, it could be run on port but to reduce tcp overhead we ran on socket.
Supervisor is used to run this gunicorn script as supervisor is simple tool which is used to control your process.
and with the help of nginx reverse proxy Our Django site was life.
For more details follow below blog.
http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/

How can I get a live reload like GAE with FALCON?

I am setting up a new project that is going to use python to build a RESTful back end. I looked at GAE, but choose Falcon Framework, because the application needs to eventually be installed on local servers. GAE has a great development feature, it allows for iterative development by watching the source, and reloading.
You can leave the web server running while you develop your
application. The web server knows to watch for changes in your source
files and reload them if necessary.
How can I set up Falcon to do the same thing?
This may not be the best answer, but I found that there is no simple method that does not require more software installed the way GAE does it, but after you install gunicorn, your can use the --reload switch and the server will auto-reload the source.
$ gunicorn -b 127.0.0.1:8000 -b [::1]:8000 --reload myapp:app
Docs: http://docs.gunicorn.org/en/19.0/settings.html#reload
Auto-reloading is not a feature of the framework (Falcon), but rather of the server. If you do want auto-reloading, the simplest way to do it is run your Falcon code on a gunicorn server, using the --reload switch. For example:
$ gunicorn --reload app:app
Assuming your API is inside app.py and named app.

Deploying Django: How do you do it?

I have tried following guides like this one but it just didnt work for me.
So my question is this: What is a good guide for deploying Django, and how do you deploy your Django.
I keep hearing that capastrano is pretty nifty to use, but i have no idea as to how to work it or what it does (apart from automation of deploying code), or even if i want/need to use it or not.
mod_wsgi in combination with a virtualenv for all the dependencies, a mercurial checkout into the virtualenv and a fabric recipe to check out the changes on the server.
I wrote an article about my usual workflow: Deploying Python Web Applications. Hope that helps.
I have had success with mod_wsgi
In my previous work we had real genius guy on deployment duties, he deployed application (Python, SQL, Perl and Java code) as set of deb files built for Ubuntu. Unfortunately now, I have no such support. We are deploying apps manually to virtualenv-ed environments with separate nginx configs for FastCGI. We use paver to deploy to remote servers. It's painful, but it works.
This looks like a good place to start: http://www.unessa.net/en/hoyci/2007/06/using-capistrano-deploy-django-apps/
I use mod_python, and have every site in a git repository with the following subdirs:
mysite
template
media
I have mysite/settings.py in .gitignore, and work like this:
do development on my local machine
create remote repository on webserver
push my changes to webserver repo
set up apache vhost config file, tweak live server settings.py
run git checkout && git reset --hard && sudo /etc/init.d/apache2 restart on webserver repo to get up-to-date version to its working copy and restart apache
repeat steps 1, 3 and 5 whenever change request comes
The easiest way would be to use one of the sites on http://djangofriendly.com/hosts/ that will provide the hosting and set up for you, but even if you're wanting to roll your own it will allow you to see what set up other sites are using.

Categories

Resources