Created
January 7, 2015 01:21
Revisions
-
cutewalker created this gist
Jan 7, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ # -*- coding: utf-8 -*- import MySQLdb import threading import time import sqlalchemy.pool MySQLdb = sqlalchemy.pool.manage(MySQLdb) #db = MySQLdb.connect("localhost", "root", "", "miztest") #cursor = db.cursor() class Runner(threading.Thread): def __init__(self, name, counts): super(Runner, self).__init__(name=name) self.counts = counts #self.db = MySQLdb.connect("localhost", "root", "", "miztest") #self.cursor = self.db.cursor() def run(self): for x in xrange(self.counts): self._do_db_thing(x) time.sleep(0.1) def _do_db_thing(self, x): sql = "insert into foo values(%s, %s)" % (self.name, x) #self.cursor.execute(sql) #self.db.commit() db = MySQLdb.connect("localhost", "root", "", "miztest") cursor = db.cursor() cursor.execute(sql) db.commit() print id(db) if __name__ == '__main__': runners = [] for x in range(1, 6): runners.append(Runner(x, 50)) for r in runners: r.start() for r in runners: r.join()