python連接池實(shí)現(xiàn)示例程序
import socket
import Queue
import threading
def worker():
while True:
i = q.get()
conn=i[0]
addr=i[1]
while 1:
sms=conn.recv(1024)
if sms!="":
print "Message from ("+str(addr[0])+":"+str(addr[1])+"): "+sms
else:
print "Close the Connection from ("+str(addr[0])+":"+str(addr[1])+")"
conn.close()
break
q.task_done()
if __name__=="__main__":
q = Queue.Queue()
thread_num=5000
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind(("",4242))
s.listen(50000)
print "Server is listening at 4242"
for _ in range(0,thread_num):
t=threading.Thread(target=worker)
t.setDaemon(1)
t.start()
while 1:
conn,addr=s.accept()
print "Connection come from ("+str(addr[0])+":"+str(addr[1])+")"
q.put((conn,addr))
q.join()
- Python實(shí)現(xiàn)Mysql數(shù)據(jù)庫(kù)連接池實(shí)例詳解
- Python MySQL數(shù)據(jù)庫(kù)連接池組件pymysqlpool詳解
- 構(gòu)建高效的python requests長(zhǎng)連接池詳解
- Python3 多線程(連接池)操作MySQL插入數(shù)據(jù)
- 分析解決Python中sqlalchemy數(shù)據(jù)庫(kù)連接池QueuePool異常
- Python 中創(chuàng)建 PostgreSQL 數(shù)據(jù)庫(kù)連接池
- python自制簡(jiǎn)易mysql連接池的實(shí)現(xiàn)示例
- Python封裝數(shù)據(jù)庫(kù)連接池詳解
相關(guān)文章
python 數(shù)據(jù)庫(kù)查詢返回list或tuple實(shí)例
這篇文章主要介紹了python 數(shù)據(jù)庫(kù)查詢返回list或tuple實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-05-05Python學(xué)習(xí)之a(chǎn)syncore模塊用法實(shí)例教程
這篇文章主要介紹了Python學(xué)習(xí)之a(chǎn)syncore模塊用法,主要講述了asyncore模塊的組成、原理及相關(guān)函數(shù)的用法,對(duì)于使用Python進(jìn)行網(wǎng)絡(luò)編程來(lái)說(shuō)非常實(shí)用,需要的朋友可以參考下2014-09-09pyqt4教程之實(shí)現(xiàn)windows窗口小示例分享
這篇文章主要介紹了pyqt4實(shí)現(xiàn)windows窗口小示例,需要的朋友可以參考下2014-03-03TensorFlow2.1.0安裝過(guò)程中setuptools、wrapt等相關(guān)錯(cuò)誤指南
這篇文章主要介紹了TensorFlow2.1.0安裝時(shí)setuptools、wrapt等相關(guān)錯(cuò)誤指南,本文通過(guò)安裝錯(cuò)誤分析給出大家解決方案,感興趣的朋友跟隨小編一起看看吧2020-04-04python模塊hashlib(加密服務(wù))知識(shí)點(diǎn)講解
在本篇文章里小編給大家分享的是關(guān)于python模塊hashlib(加密服務(wù))知識(shí)點(diǎn)內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。2019-11-11移動(dòng)測(cè)試開(kāi)發(fā)Mitmproxy用于測(cè)試抓包神器詳解
這篇文章主要為大家介紹了python移動(dòng)測(cè)試開(kāi)發(fā)Mitmproxy抓包神器使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06