ftplib.FTP timeout has inconsistent behaviour

后端 未结 2 792
清酒与你
清酒与你 2021-01-20 02:20

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 wr

2条回答
  •  滥情空心
    2021-01-20 02:37

    From ftplib.FTP docs:

    The optional timeout parameter specifies a timeout in seconds for blocking operations like the connection attempt

    i.e., the timeout may limit individual socket operations but it says nothing about the duration of the FTP() call itself.

    As @user590028 pointed out: FTP calls (indirectly) socket.create_connection() that may invoke several blocking operations in sequence and it may succeed if each operation takes less than timeout seconds even if all operations combined take longer.

    If you want to enforce the total timeout, see Timeout on a Python function call.

提交回复
热议问题