开发者

Program gets stuck attempting to create NNTP connection

开发者 https://www.devze.com 2023-03-02 21:03 出处:网络
My program starts a connection to a usenet server like this: s = nntplib.NNTP(self.nserver, 119, self.nuser, self.npass)

My program starts a connection to a usenet server like this:

s = nntplib.NNTP(self.nserver, 119, self.nuser, self.npass)

But sometimes there's a problem. The connection is not made and the program waits for a response indefinitely.

How can 开发者_如何学PythonI make it check for a timeout?


It is not the proper solution, but try to set a timeout to the socket module :

import socket

orig_timeout = socket.getdefaulttimeout(timeout)
socket.setdefaulttimeout(timeout)

s = nntplib.NNTP(self.nserver, 119, self.nuser, self.npass)

socket.setdefaulttimeout(orig_timeout)
0

精彩评论

暂无评论...
验证码 换一张
取 消