自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Python數(shù)據(jù)庫連接池相關(guān)示例詳細(xì)介紹

開發(fā) 后端
以下的內(nèi)容主要是介紹Python數(shù)據(jù)庫連接池應(yīng)用于多線程環(huán)境中使用的具體方案的具體介紹。你就可以點擊以下的文章,對其進(jìn)行了解。

下面的內(nèi)容主要是介紹Python數(shù)據(jù)庫連接池應(yīng)用于多線程環(huán)境中使用的具體方案的具體介紹。如果你對Python數(shù)據(jù)庫連接池在其具體方案應(yīng)用的相關(guān)步驟感興趣的話,你就可以點擊以下的文章,對其進(jìn)行了解。

示例:

  1. #-*-coding:utf-8-*-  
  2. import threading,time,datetime  
  3. import MySQLdb  
  4. from DBUtils import PooledDB  
  5. pool = PooledDB.PooledDB(MySQLdb,100,50,100,490,False,
    host='localhost',user='root',passwd='321',db='test',
    charset='utf8')   

默認(rèn)打開的時候就創(chuàng)建了100個數(shù)據(jù)庫連接。檢查發(fā)現(xiàn)果然數(shù)據(jù)庫中有100個

 

  1. class MyThread(threading.Thread):  
  2. def __init__(self,threadName):  
  3. self.conn = pool.connection()    

 

直接從數(shù)據(jù)庫連接池中提取

 

  1. threading.Thread.__init__(self,name=threadName)  
  2. def run(self):  
  3. cursor=self.conn.cursor()  
  4. print "hello--->",self.getName()  
  5. file_objct = open('8.txt','a+')  
  6. file_objct.write(self.getName()+'\n')  
  7. file_objct.close()  
  8. #cursor.execute("call loaddate();")  
  9. #self.conn.commit()  
  10. time.sleep(10)  
  11. def __del__(self):  
  12. self.conn.close()  
  13. self.conn = None   
  14. for i in range(5):  
  15. obj = MyThread(str(i))  
  16. obj.start()  
  17.  

 

 

 

如果我開480個線程的話 數(shù)據(jù)庫顯示的正是480個連接!maxconnections: ***允許連接數(shù)量(缺省值 0 代表不限制)如果我現(xiàn)在將代碼調(diào)整如下:

 

  1. #-*-coding:utf-8-*-  
  2. import threading,time,datetime  
  3. import MySQLdb  
  4. from DBUtils import PooledDB  
  5. pool = PooledDB.PooledDB(MySQLdb,100,50,100,400,False,
    host='localhost',user='root',passwd='321',db='test',
    charset='utf8')  
  6. class MyThread(threading.Thread):  
  7. def __init__(self,threadName):  
  8. self.conn = pool.connection()   
  9. threading.Thread.__init__(self,name=threadName)  
  10. def run(self):  
  11. cursor=self.conn.cursor()  
  12. print "hello--->",self.getName()  
  13. file_objct = open('8.txt','a+')  
  14. file_objct.write(self.getName()+'\n')  
  15. file_objct.close()  
  16. #cursor.execute("call loaddate();")  
  17. #self.conn.commit()  
  18. time.sleep(10)  
  19. def __del__(self):  
  20. self.conn.close()  
  21. self.conn = None   
  22. for i in range(402):  
  23. obj = MyThread(str(i))  
  24. obj.start()   

 

連接池***的數(shù)目才400 。

【編輯推薦】

  1. Python復(fù)制文件的實際操作方案與代碼詳解
  2. Python 文件相關(guān)實際應(yīng)用方案與代碼詳解
  3. Python open讀寫文件的實際應(yīng)用方案詳解
  4. Python socket編程在具體應(yīng)用中前兩個步驟的介紹
  5. Python Library中Condition的具體操作方案
責(zé)任編輯:佚名 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2009-06-24 07:53:47

Hibernate數(shù)據(jù)

2010-03-18 15:09:15

python數(shù)據(jù)庫連接

2017-06-22 14:13:07

PythonMySQLpymysqlpool

2009-08-10 17:34:42

C#數(shù)據(jù)庫連接池

2019-11-27 10:31:51

數(shù)據(jù)庫連接池內(nèi)存

2009-06-16 09:25:31

JBoss配置

2018-10-10 14:27:34

數(shù)據(jù)庫連接池MySQL

2021-08-12 06:52:01

.NET數(shù)據(jù)庫連接池

2020-04-30 14:38:51

數(shù)據(jù)庫連接池線程

2011-08-09 15:25:14

線程池數(shù)據(jù)庫連接池

2009-07-29 09:33:14

ASP.NET數(shù)據(jù)庫連

2018-01-03 14:32:32

2009-07-17 13:32:49

JDBC數(shù)據(jù)庫

2011-05-19 09:53:33

數(shù)據(jù)庫連接池

2025-01-16 10:30:49

2011-07-29 15:11:42

WeblogicOracle數(shù)據(jù)庫連接

2011-06-23 09:00:04

QT QODBC 數(shù)據(jù)庫

2009-12-29 11:15:45

ADO數(shù)據(jù)庫

2009-07-03 17:37:54

JSP數(shù)據(jù)庫

2009-01-15 09:02:27

JMXJBossJMX監(jiān)控
點贊
收藏

51CTO技術(shù)棧公眾號