日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python數(shù)據(jù)庫連接池相關(guān)示例詳細(xì)介紹

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

“專業(yè)、務(wù)實(shí)、高效、創(chuàng)新、把客戶的事當(dāng)成自己的事”是我們每一個(gè)人一直以來堅(jiān)持追求的企業(yè)文化。 成都創(chuàng)新互聯(lián)是您可以信賴的網(wǎng)站建設(shè)服務(wù)商、專業(yè)的互聯(lián)網(wǎng)服務(wù)提供商! 專注于網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、軟件開發(fā)、設(shè)計(jì)服務(wù)業(yè)務(wù)。我們始終堅(jiān)持以客戶需求為導(dǎo)向,結(jié)合用戶體驗(yàn)與視覺傳達(dá),提供有針對(duì)性的項(xiàng)目解決方案,提供專業(yè)性的建議,創(chuàng)新互聯(lián)建站將不斷地超越自我,追逐市場,引領(lǐng)市場!

示例:

 
 
 
  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)打開的時(shí)候就創(chuàng)建了100個(gè)數(shù)據(jù)庫連接。檢查發(fā)現(xiàn)果然數(shù)據(jù)庫中有100個(gè)

 
 
 
  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()

如果我開480個(gè)線程的話 數(shù)據(jù)庫顯示的正是480個(gè)連接!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 。


網(wǎng)站名稱:Python數(shù)據(jù)庫連接池相關(guān)示例詳細(xì)介紹
本文路徑:http://www.dlmjj.cn/article/dppehcs.html