日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux多少个端口,Linux允许python使用多少个网络端口?

發布時間:2024/10/5 linux 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux多少个端口,Linux允许python使用多少个网络端口? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

所以我一直在嘗試在

python中多線程一些互聯網連接.我一直在使用多處理模塊,所以我可以繞過“Global Interpreter Lock”.但似乎系統只為python提供了一個開放的連接端口,或者至少它只允許一次連接發生.這是我所說的一個例子.

*請注意,這是在Linux服務器上運行

from multiprocessing import Process,Queue

import urllib

import random

# Generate 10,000 random urls to test and put them in the queue

queue = Queue()

for each in range(10000):

rand_num = random.randint(1000,10000)

url = ('http://www.' + str(rand_num) + '.com')

queue.put(url)

# Main funtion for checking to see if generated url is active

def check(q):

while True:

try:

url = q.get(False)

try:

request = urllib.urlopen(url)

del request

print url + ' is an active url!'

except:

print url + ' is not an active url!'

except:

if q.empty():

break

# Then start all the threads (50)

for thread in range(50):

task = Process(target=check,args=(queue,))

task.start()

因此,如果你運行它,你會注意到它在函數上啟動了50個實例,但一次只運行一個.您可能認為“全球口譯員鎖”正在這樣做但事實并非如此.嘗試將函數更改為數學函數而不是網絡請求,您將看到所有50個線程同時運行.

那么我必須使用套接字嗎?或者我能做些什么可以讓python訪問更多端口?或者有什么我沒有看到的?讓我知道你的想法!謝謝!

*編輯

所以我編寫了這個腳本來更好地使用請求庫進行測試.好像我之前沒有對它進行過這樣的測試. (我主要使用urllib和urllib2)

from multiprocessing import Process,Queue

from threading import Thread

from Queue import Queue as Q

import requests

import time

# A main timestamp

main_time = time.time()

# Generate 100 urls to test and put them in the queue

queue = Queue()

for each in range(100):

url = ('http://www.' + str(each) + '.com')

queue.put(url)

# Timer queue

time_queue = Queue()

# Main funtion for checking to see if generated url is active

def check(q,t_q): # args are queue and time_queue

while True:

try:

url = q.get(False)

# Make a timestamp

t = time.time()

try:

request = requests.head(url,timeout=5)

t = time.time() - t

t_q.put(t)

del request

except:

t = time.time() - t

t_q.put(t)

except:

break

# Then start all the threads (20)

thread_list = []

for thread in range(20):

task = Process(target=check,time_queue))

task.start()

thread_list.append(task)

# Join all the threads so the main process don't quit

for each in thread_list:

each.join()

main_time_end = time.time()

# Put the timerQueue into a list to get the average

time_queue_list = []

while True:

try:

time_queue_list.append(time_queue.get(False))

except:

break

# Results of the time

average_response = sum(time_queue_list) / float(len(time_queue_list))

total_time = main_time_end - main_time

line = "Multiprocessing: Average response time: %s sec. -- Total time: %s sec." % (average_response,total_time)

print line

# A main timestamp

main_time = time.time()

# Generate 100 urls to test and put them in the queue

queue = Q()

for each in range(100):

url = ('http://www.' + str(each) + '.com')

queue.put(url)

# Timer queue

time_queue = Queue()

# Main funtion for checking to see if generated url is active

def check(q,timeout=5)

t = time.time() - t

t_q.put(t)

del request

except:

t = time.time() - t

t_q.put(t)

except:

break

# Then start all the threads (20)

thread_list = []

for thread in range(20):

task = Thread(target=check,time_queue))

task.start()

thread_list.append(task)

# Join all the threads so the main process don't quit

for each in thread_list:

each.join()

main_time_end = time.time()

# Put the timerQueue into a list to get the average

time_queue_list = []

while True:

try:

time_queue_list.append(time_queue.get(False))

except:

break

# Results of the time

average_response = sum(time_queue_list) / float(len(time_queue_list))

total_time = main_time_end - main_time

line = "Standard Threading: Average response time: %s sec. -- Total time: %s sec." % (average_response,total_time)

print line

# Do the same thing all over again but this time do each url at a time

# A main timestamp

main_time = time.time()

# Generate 100 urls and test them

timer_list = []

for each in range(100):

url = ('http://www.' + str(each) + '.com')

t = time.time()

try:

request = requests.head(url,timeout=5)

timer_list.append(time.time() - t)

except:

timer_list.append(time.time() - t)

main_time_end = time.time()

# Results of the time

average_response = sum(timer_list) / float(len(timer_list))

total_time = main_time_end - main_time

line = "Not using threads: Average response time: %s sec. -- Total time: %s sec." % (average_response,total_time)

print line

如您所見,它是多線程的.實際上,我的大部分測試表明,線程模塊實際上比多處理模塊更快. (我不明白為什么!)以下是我的一些結果.

Multiprocessing: Average response time: 2.40511314869 sec. -- Total time: 25.6876308918 sec.

Standard Threading: Average response time: 2.2179402256 sec. -- Total time: 24.2941861153 sec.

Not using threads: Average response time: 2.1740363431 sec. -- Total time: 217.404567957 sec.

這是在我的家庭網絡上完成的,我服務器上的響應時間要快得多.我認為我的問題是間接回答的,因為我在一個更復雜的腳本上遇到了問題.所有的建議都幫助我很好地優化了它.謝謝大家!

總結

以上是生活随笔為你收集整理的linux多少个端口,Linux允许python使用多少个网络端口?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产一区在线看 | 1级av | 久久亚洲网 | 蜜臀视频一区二区三区 | 丰满的人妻hd高清日本 | 久久精品无码一区二区三区免费 | 亚洲综合免费观看高清完整版在线 | 天堂综合网久久 | 性色av一区二区三区红粉影视 | 天堂资源在线观看 | 激情xxx | 久福利| 欧美猛男gaygay | 一区二区三区在线免费观看视频 | 亚洲成人网络 | 97精品一区二区视频在线观看 | 国产高潮呻吟久久 | 免费的毛片视频 | 成人mv | 欧美综合亚洲 | 亚洲国产精品久久久久婷婷老年 | 91免费版黄 | 亚洲一区国产 | 日韩一区二区三区视频在线 | 欧美顶级metart裸体全部自慰 | 无码精品一区二区三区在线播放 | 国产交换配乱淫视频免费 | 人人人插 | 日韩男人的天堂 | 95精品视频 | 黄色资源网站 | 九九热视频免费观看 | 色网导航站| 久热精品视频在线播放 | 欧美色欧美色 | 懂色av懂色av粉嫩av分享吧 | 亚洲视频一二 | 国产精品久久久久久久久免费软件 | avav国产 | 91亚洲国产成人久久精品网站 | 久久中文免费视频 | 岳狂躁岳丰满少妇大叫 | 久久免费福利视频 | 亚洲视频在线免费 | 日本aa视频| 亚洲色图清纯唯美 | 黄色福利网站 | 天天干视频在线观看 | 秘密基地电影免费版观看国语 | 久久中文在线 | 最近日韩中文字幕中文 | 中文字幕有码av | 95在线视频 | 黄色网战入口 | h视频免费在线 | 一级片视频免费观看 | 欧美一级片在线看 | 91高清在线免费观看 | 夜夜操夜夜摸 | 优优色影院 | 久草青青视频 | 欧美刺激性大交 | 色噜噜狠狠一区二区三区 | 99re6在线视频 | 在线你懂的 | 亚洲精品观看 | 蜜臀aⅴ免费一区二区 | 欧美成人免费在线观看视频 | 亚洲高清天堂 | 欧美性xxxx| 成人网色 | 91在线导航 | 日本大尺度电影免费观看全集中文版 | av在线高清观看 | 久久久久久在线观看 | 亚洲中文字幕无码不卡电影 | 成人黄页 | 超碰超碰97 | 免费在线观看成人av | 2019毛片| 日韩精品视频一区二区 | 五月天激情丁香 | 色视频免费 | 寂寞人妻瑜伽被教练日 | 这里只有精品免费视频 | 爽爽爽av| 日韩三级视频在线观看 | 国产精久久久 | 视频一区三区 | 国产剧情精品在线 | 理论黄色片 | 99热免费在线 | 顶级黄色片 | 国产色图视频 | av观看网| 人人干网站 | 肥臀熟女一区二区三区 | 最近中文字幕mv免费高清在线 | 日韩成人一区二区视频 |