Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的程序像这样开始连接到 usenet 服务器:
s = nntplib.NNTP(self.nserver, 119, self.nuser, self.npass)
但有时会出现问题。未建立连接,程序无限期地等待响应。
我怎样才能让它检查超时?
这不是正确的解决方案,但尝试为套接字模块设置超时:
import socket orig_timeout = socket.getdefaulttimeout(timeout) socket.setdefaulttimeout(timeout) s = nntplib.NNTP(self.nserver, 119, self.nuser, self.npass) socket.setdefaulttimeout(orig_timeout)