首页 > 数据库技术 > 详细

关于PooledDB使用autocommit的方法

时间:2016-01-20 22:58:03      阅读:715      评论:0      收藏:0      [点我收藏+]

在Python里,普通使用数据库,可以通过调用connection里的autocommit函数来设置是否打开自动更新


self._db = MySQLdb.connect(**self._db_args)
self._db.autocommit(True)

但是如果使用了线程池PooledDB,则不能使用线程池返回的connection来设置,而是在创建线程池的时候来进行设置

self.__pool = PooledDB(creator=MySQLdb, mincached=1 , maxcached=20 ,host=DBHOST , port=DBPORT , user=DBUSER , passwd=DBPWD ,db=DBNAME,use_unicode=False,charset=DBCHAR,cursorclass=DictCursor,setsession=[‘SET AUTOCOMMIT = 1‘])

其中的

setsession=[‘SET AUTOCOMMIT = 1‘]

就是用来设置线程池是否打开自动更新的配置,0为False,1为True

本文出自 “月之影·影之海” 博客,请务必保留此出处http://abyss.blog.51cto.com/3625755/1736844

关于PooledDB使用autocommit的方法

原文:http://abyss.blog.51cto.com/3625755/1736844

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!