#!/bin/python
from sqlalchemy.pool import QueuePool
import threading
import MySQLdb
import time
def creator():
c = MySQLdb.connect(host="192.168.41.76", db="test", user="root", passwd="root", port=3306)
return c
pool = QueuePool(creator, pool_size=2, max_overflow=0, timeout=1)
class Demo(object):
def proc(self):
ident = threading.currentThread().getName()
conn = pool.connect()
print ident, id(conn), id(conn.connection)
cur = conn.cursor()
cur.execute("select * from t_user")
res = cur.fetchall()
# conn.close()
time.sleep(2)
def __del__(self):
print "__del__"
def target():
while True:
try:
ident = threading.currentThread().getName()
d = Demo()
d.proc()
# conn = pool.connect()
mysql连接池, 连接的释放, 连接的回收, 连接释放机制
最新推荐文章于 2024-04-09 16:55:06 发布