久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

ftplib.FTP 超時行為不一致

ftplib.FTP timeout has inconsistent behaviour(ftplib.FTP 超時行為不一致)
本文介紹了ftplib.FTP 超時行為不一致的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在嘗試使用帶有超時選項的 ftplib.FTP() 作為特定主機名的超時值.但我正在經(jīng)歷奇怪的行為.為了測試它,我編寫了一段非常簡單的代碼.

I am trying to use ftplib.FTP() with timeout option as some timeout value for a particular hostname. But i am experiencing weird behaviour. To test it i have written a very simple piece of code.

import ftplib
from ftplib import FTP
ftp = ftplib.FTP("google.com",timeout=2)

API文檔說以秒為單位輸入超時值,但似乎需要更長的時間,對我來說幾乎需要8秒以上.誰能解釋一下這個行為.我正在使用 python2.7

The API document says to enter timeout value in seconds, but it seems that it takes longer than that, for me it almost takes more than 8 secs. Can anybody please explain the behaviour.I am using python2.7

推薦答案

ftplib.FTP 調(diào)用 socket.create_connection().根據(jù)到文檔 https://docs.python.org/2/library/socket.html#socket.create_connection

ftplib.FTP invokes socket.create_connection(). According to the docs https://docs.python.org/2/library/socket.html#socket.create_connection

如果主機是非數(shù)字主機名,它將嘗試為兩者解析AF_INET 和 AF_INET6,然后嘗試連接所有可能的依次分配地址,直到連接成功.

if host is a non-numeric hostname, it will try to resolve it for both AF_INET and AF_INET6, and then try to connect to all possible addresses in turn until a connection succeeds.

快速檢查 google.com 將顯示大約一打(或更多)取決于您所在國家/地區(qū)的地區(qū).你的 2 秒超時應(yīng)用于每個主機.

A quick check of google.com will show about a dozen (or more) depending on your region of the country. Your 2 second timeout is applied to each of the hosts.

如果您想將總時間限制為 2 秒,請先進行查找并將數(shù)字地址傳遞給您的 ftplib.FTP 調(diào)用:

If you want to limit total time to 2 seconds, do the lookup first and pass the numeric address to your ftplib.FTP call:

import socket, ftplib
host = socket.gethostbyname('google.com')
ftp = ftplib.FTP(host, timeout=2)

這篇關(guān)于ftplib.FTP 超時行為不一致的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Why I cannot make an insert to Python list?(為什么我不能插入 Python 列表?)
Insert a column at the beginning (leftmost end) of a DataFrame(在 DataFrame 的開頭(最左端)插入一列)
Python psycopg2 not inserting into postgresql table(Python psycopg2 沒有插入到 postgresql 表中)
list extend() to index, inserting list elements not only to the end(list extend() 索引,不僅將列表元素插入到末尾)
How to add element in Python to the end of list using list.insert?(如何使用 list.insert 將 Python 中的元素添加到列表末尾?)
TypeError: #39;float#39; object is not subscriptable(TypeError:“浮動對象不可下標(biāo))
主站蜘蛛池模板: av片网| 国产一极毛片 | 天堂网色 | 久久久久久久久久久丰满 | 成人毛片视频免费 | 成人国产一区二区三区精品麻豆 | 国产精品欧美一区二区三区不卡 | 超碰在线网站 | 岛国av在线免费观看 | 精品久久久久久 | 久久99精品国产 | 美女国产精品 | 欧洲妇女成人淫片aaa视频 | 国产一区二区影院 | 国产一区二区精品在线观看 | 美女久久 | 国产精品亚洲视频 | 综合久久综合久久 | 一区中文字幕 | 日韩成人免费av | 丝袜美腿一区 | 欧美一区中文字幕 | 成人av一区二区亚洲精 | 羞羞视频网站免费观看 | 成人免费视屏 | 国产精品美女www爽爽爽 | 国产在线拍偷自揄拍视频 | 欧美成人精品一区二区男人看 | 一级大片免费 | 精品久久久久久久久久久久 | 99九九视频| 成人深夜福利 | 日韩欧美一区在线 | 天天综合网天天综合 | 色就是色欧美 | 亚洲一区国产 | 怡红院怡春院一级毛片 | 99精品电影 | 日韩在线观看网站 | 午夜ww | 91在线|