久久久久久久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:“浮動對象不可下標)
主站蜘蛛池模板: 亚洲欧美激情国产综合久久久 | 欧美在线视频一区二区 | 国产中文视频 | 免费一级欧美在线观看视频 | 激情五月婷婷 | 91精品国产综合久久婷婷香蕉 | 日韩电影免费在线观看中文字幕 | 91久久精品一区二区二区 | 久久久久久久一区 | 亚洲第一成人av | 国产精品久久久久久久三级 | 亚洲一区二区视频 | 欧美日韩在线一区 | 男女羞羞视频大全 | 人操人免费视频 | 亚洲一区视频在线播放 | 伦理片97 | 久久精品二区 | 伊人色综合久久久天天蜜桃 | 91精品国产色综合久久不卡98口 | 麻豆久久| 日韩精品免费 | 91麻豆精品国产91久久久更新资源速度超快 | 午夜影视大全 | 久久精品亚洲国产奇米99 | 欧美在线免费 | 久久国产综合 | 欧美精品一区二区免费视频 | 91精品国产自产精品男人的天堂 | 中文二区 | 亚洲成av人片在线观看无码 | 亚洲国产一区二区三区 | 婷婷久久网 | 一区二区三区回区在观看免费视频 | 亚洲日本视频 | 欧洲成人午夜免费大片 | 亚洲三区视频 | 亚洲欧洲国产视频 | 欧美一级大片免费观看 | 中文字幕亚洲一区二区三区 | 久久成 |