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

ftplib.FTP 超時行為不一致

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

問題描述

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

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 調用 socket.create_connection().根據到文檔 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

如果主機是非數字主機名,它將嘗試為兩者解析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 將顯示大約一打(或更多)取決于您所在國家/地區的地區.你的 2 秒超時應用于每個主機.

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 秒,請先進行查找并將數字地址傳遞給您的 ftplib.FTP 調用:

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)

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

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

相關文檔推薦

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:“浮動對象不可下標)
主站蜘蛛池模板: 国产精品黄 | www久久久| 亚洲一区二区国产精品 | 国产一区二区免费看 | 国产香蕉av | 香蕉视频免费 | 亚洲涩涩涩 | 国产视频一二区 | 日韩精品在线看 | 五月婷婷 | 午夜精品视频 | 狠狠干网 | 日韩精品网站 | 高跟肉丝丝袜呻吟啪啪网站av | 一级片欧美 | 日韩免费视频一区二区 | 国产欧美日韩在线视频 | 亚洲精品欧美 | 麻豆一区二区三区四区 | 操操影院 | 9.1成人免费看片 | 亚洲精品久久久久 | 日韩精品一区在线观看 | 九九精品免费视频 | 久久精品导航 | 一区二区免费视频 | 九九热在线视频观看 | 中文字幕网站 | 中文字幕日韩视频 | 午夜看看 | 国产欧美欧洲 | 欧美日韩一区二区三区四区 | 亚洲天堂免费 | 日本视频一区二区三区 | 国产乱码一区二区三区 | www.色综合| 国产午夜在线 | 成人福利| 国产午夜精品视频 | 成人午夜免费视频 | 国产视频h|