Posts

Showing posts with the label python

Deploy Python Application with Gunicorn and Supervisor on Ubuntu

Suppose we have to deploy 3 python applications on a Ubuntu server. The applications and their python versions are as follows: 1. Analytics application (analytics.example.com): python2 2. Android API (android.example.com): python3.5 3. Auth API (auth.example.com): python3.6 What will be the solution? How can we run 3 different python applications on 3 different python versions on same machine? Here is a simple solution to achieve this goal. I'm assuming you know about python virtual environments and wsgi. If not Google will help you on this. The following steps should work with most of Ubuntu versions. Here are our plans to achieve our goal: 1. We'll create 3 separate virtual environment to run these applications 2. We'll use gunicorn inside these virtual environments to run these applications on 3 different ports e.g. 8001, 8002, 8003 3. We'll use supervisor to start, stop and monitor these 3 applications running on gunicorn Lets assume we've the co...

Print a progress in Python

Here is how to do this: import sys sys.stdout.write("\r%d" % i) sys.stdout.flush() Writing '\r' will move the cursor back to the beginning of the line. If we want to print a %, we need to print an additional % like the folllowing: sys.stdout.write("\r%d%%" % i)

Integrating Python and Apache

Today I'm going to write on how to integrate Python with apache web server. All you probably know that Python is also a server side scripting language. So, like PHP and other server side scripting languages, you can use Python in the same way. This is not tough, just a matter of some minutes. Okay, before you start the tutorial, you must (most probably already you have) have the following installed in your computer/server. 1. Apache web server (Only apache or xampp, wamp etc anything containing apache will do). I'll use xampp as reference but others should behave the same 2. Python (I'm using 2.7) So, if you don't have these two installed, download and install them first and then continue As you are here, you have already installed apache/xampp/wamp and Python. Follow these steps 1. Go to your apache folder. In my case, as I'm using xampp it's in location C:\xampp\apache 2. Go to the conf folder and open the httpd.conf using a text editor. I pref...