久久久久久久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))
主站蜘蛛池模板: 国产一级特黄aaa大片评分 | 日韩av成人在线观看 | 日韩精品二区 | 色在线免费 | 亚洲欧美国产毛片在线 | av激情在线 | 视频1区2区 | 99这里只有精品视频 | 日韩精品不卡 | 久久久久久国产精品久久 | 欧美亚洲综合久久 | 91精品国产自产在线老师啪 | 午夜小视频在线观看 | 久久综合久久久 | 一区二区三区四区毛片 | 亚洲成网站| 日韩精品av| 成人免费淫片aa视频免费 | 国产高清久久久 | 美女激情av| 另类专区成人 | 久久这里有精品 | 免费黄色网址视频 | 日韩欧美1区2区 | 日韩视频在线一区 | 中文字幕第一页在线 | 中文二区 | 免费99精品国产自在在线 | 国产一区二区在线播放 | 欧美黄在线观看 | 在线激情视频 | 免费黄篇 | 国产a级黄色录像 | 看片国产| 天天天堂| 一区二区三区四区av | 成人av在线播放 | 伊人精品在线 | 99国产精品久久久久 | 精品国产乱码久久久久久中文 | 少妇av片|