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ù)庫連接池實(shí)例詳解
- Python MySQL數(shù)據(jù)庫連接池組件pymysqlpool詳解
- 構(gòu)建高效的python requests長連接池詳解
- Python3 多線程(連接池)操作MySQL插入數(shù)據(jù)
- 分析解決Python中sqlalchemy數(shù)據(jù)庫連接池QueuePool異常
- Python 中創(chuàng)建 PostgreSQL 數(shù)據(jù)庫連接池
- python自制簡易mysql連接池的實(shí)現(xiàn)示例
- Python封裝數(shù)據(jù)庫連接池詳解
相關(guān)文章
python 數(shù)據(jù)庫查詢返回list或tuple實(shí)例
這篇文章主要介紹了python 數(shù)據(jù)庫查詢返回list或tuple實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05
Python學(xué)習(xí)之a(chǎn)syncore模塊用法實(shí)例教程
這篇文章主要介紹了Python學(xué)習(xí)之a(chǎn)syncore模塊用法,主要講述了asyncore模塊的組成、原理及相關(guān)函數(shù)的用法,對于使用Python進(jìn)行網(wǎng)絡(luò)編程來說非常實(shí)用,需要的朋友可以參考下2014-09-09
pyqt4教程之實(shí)現(xiàn)windows窗口小示例分享
這篇文章主要介紹了pyqt4實(shí)現(xiàn)windows窗口小示例,需要的朋友可以參考下2014-03-03
TensorFlow2.1.0安裝過程中setuptools、wrapt等相關(guān)錯(cuò)誤指南
這篇文章主要介紹了TensorFlow2.1.0安裝時(shí)setuptools、wrapt等相關(guān)錯(cuò)誤指南,本文通過安裝錯(cuò)誤分析給出大家解決方案,感興趣的朋友跟隨小編一起看看吧2020-04-04
python模塊hashlib(加密服務(wù))知識點(diǎn)講解
在本篇文章里小編給大家分享的是關(guān)于python模塊hashlib(加密服務(wù))知識點(diǎn)內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。2019-11-11

