gpt4 book ai didi

python - 套接字连接的范围是什么?

转载 作者:行者123 更新时间:2023-12-03 12:02:10 27 4
gpt4 key购买 nike

我对python中套接字连接对象的范围有疑问。
如果我们在socket.setdefaulttimeout(seconds)类中全局设置A,是否会影响在A类中初始化的类的实例所执行的第三个API调用和网络调用?

最佳答案

是的,默认超时将影响在同一进程中创建的所有新套接字,因此请说the documentation:

Set the default timeout in seconds (float) for new socket objects. When the socket module is first imported, the default is None. See settimeout() for possible values and their respective meanings.


如果您不希望默认超时影响它们,则您的类可能应该设置和管理自己的套接字超时(使用 per-socket socket.socket.settimeout() method)。

关于python - 套接字连接的范围是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64719339/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com