0

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 I make it check for a timeout?

Jelle De Loecker
  • 20,999
  • 27
  • 100
  • 142

1 Answers1

2

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)
Cédric Julien
  • 78,516
  • 15
  • 127
  • 132