Posts

Showing posts with the label Python

Returning to Python

After a couple of years or so, I starting making use Python as my main programming language for one of the projects. This time I was making use of the virtualenv to install Python with various modules and just tar it up and copy to different machines. virtualenv saved me tons of time.

Broken pipe error in Flask server

I am using Flask for some of my internal services. If you haven't used Flask , I would absolutely recommend that you check it out. Recently I got the following error while I was attempting to serve a page from template. In an attempt to troubleshoot the error, I wasted almost half an hour. 127.0.0.1 - - [19/Jun/2012 17:48:37] "POST /" 500 - ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 55176) Traceback (most recent call last): File "/usr/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock self.process_request(request, client_address) File "/usr/lib/python2.7/SocketServer.py", line 310, in process_request self.finish_request(request, client_address) File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib/python2.7/SocketServer.py", line 64...

Bottle - A simple web framework in Python

I recently came across the Bottle . It is a web framework written in Python. Its very simple to learn and use. It is ideal for prototyping kind of work or you want to run a web application in no time.

Why Python has both lists and tuples?

There is a FAQ entry that explains why Python has both list and tuple data types and what is the key difference between these two types.

Django tutorial

I manged to complete the three parts Django tutorial today. I haven't worked with many web frameworks before. I have a very good experience in CGI and some flaky experience in JSP and PHP. I liked Django for the reason that they coupled the model and the database and provide the ability to almost worry nothing about writing database queries. I don't know how much more time it would have taken if I had written the poll application myself in either JSP or CGI. Especially setting up the database and the tables. Now that I have first hand experience in developing application in Django, I am yet to see the performance under reasonable and heavy loads. I am also yet to discover how Django is deployed in production. As per my understanding, the design of the Python interpreter itself is not suitable for multi-threaded applications. The best way to scale Python is not to create a multi-threaded application, but to have more instances of Python running with some load balancing server i...

Installing matplotlib - the hard way

I recently installed matplotlib from the source. It was quite an experience that I thought I would share my experience so that others don't have to waste time searching how to do that. So here it is! What is matplotlib? Matplotlib is a libarary to plot figures from your Python program. It has much more features than just plotting. You can read more about that from the library's home page . If you are planning to install matplotlib on Linux everything from the source by building everything yourself, this guide is for you. Please read on. You will have to install the dependencies first before you can install matplotlib. Matplotlib depends on numpy, zlib, libpng and FreeType libraries. You can get the full dependency list (including the optional dependent libraries) from here . Let us see how to install each one of these components. Phase 1: Installing numpy Numpy requires the same Fortran compiler that was used to build blas. There are two flavors of Fortran compilers possible: ...

Global Interpreter Lock in Python

Recently we were having an interesting discussion in our team about the threading and performance in Python. One of the key concerns was the Global Interpreter Lock (GIL) in Python. GIL is acquired before any thread accesses any of the Python objects. So if you are writing any C extensions and if you would like to manipulate any Python object, you must first acquire the lock and then only you can read/write/modify any object. Due to this, you will always have considerable of your code sequential. There is a lot of discussion about GIL on the web. You will particularly find this page useful . Someone suggested that Lua , by design, doesn't have any such constraints. It performs very well when it comes to multithreading. As I don't have much experience in programming in Lua, I don't know if that claim is true or not. I am also not sure if Perl has any such global locks issue. I tried to Google it, but didn't find anything useful.