Python MySQL Connection Pool

July 25th, 2007 by NerdyNick

I have updated this library and changed its name. To download the new version go to http://code.google.com/p/pysqlpool/. Read more on the changes

Recently I have been working on a Python application that required the use of connection pool to help speed up the processing time of the whole application. As making a new connection to the Database takes a lot of time. A connection pool is one of the best things to do to help speed this up.

I started to look all over the net and really never found out any good ideas for one that would support threading. So I set out to create my own. So here is what I came up with. MySQLPool Source

The MySQLPool class is the primary class for managing all the connections. It is never touched outside of the MySQL class. The MySQLPool class uses The Borg Pattern to store all the connections between all the instances and threads. As well as uses the Threading.Condition() to lock each connection as well as the connection dictionary.

The MySQL class is the primary class used by all the queries though out each thread and class. Each time you need to run a query. You create a new instance of MySQL passing it all your connection information in the form of a dictionary. Then call the query function with your SQL and replacement arguments (Just as if you where using the native cursor.execute() function).

When use correctly all your threads will be able to share the same connections and help speed things up.

Example:

from MySQLPool import *

conn= {”host”:”localhost”,”user”:”root”,”passwd”:”python”,”db”:”companies”}
query = MySQL(conn, True)
query.Query(”select * from company where company_id = %s”, (self.company_id))

if (int(query.rowcount) > 0):
   for row in query.record:
      print row["company"]

Source Distro Package: MySQLPool-1.0.zip
Linux Tar package to come soon.

Posted in Projects | 1 Comments

Microsoft Writeup

July 25th, 2007 by NerdyNick

Recently I had the joy of having Microsoft do a write up on my Virtual Earth property search mash-up I did. They contacted The Group Inc about how its helped them out. They looked into how its helped out there customers find there new homes and what they have been liking about the ability to find real estate this way.

You can check out the write up at: http://dev.live.com/blogs/mashups/archive/2007/07/20/125.aspx

Posted in Misc. News, Projects | 0 Comments

PyXML 0.8.4 for Windows and Python 2.5

July 16th, 2007 by NerdyNick

Well after trying to install PyXML 0.8.4 on my work computer and having no success do to the fact I don’t have Visual Studio. I have built a Windows Install for all that wish to use PyXML with there Python 2.5 installation.

As many of you will find out the PyXML project is no longer being maintained by the development crew. So finding a binary distribution of PyXML for Python 2.5 is hard. So to help in the struggle I have built the binary distribution for all to download. Please keep in mind this is really the first time I have created a binary installation for Python. So if something doesn’t work I’m sorry. Please comment back to this post and I will see what I can do.

Download: PyXML 0.8.4 for Win32 and Python 2.5

Please enjoy and keep up the Python work.

Posted in Misc. News, Projects | 8 Comments