steve at holdenweb.com
Fri Mar 3 16:02:29 CET 2006
Luis P. Mendes wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> I've developed a program that uses a socket to receive information 24h a
> ~ day.
> The problem is that the socket seems to freeze. By that I mean the
> program stops getting information but doesn't raise any error.
> I tried to solve this by writing the following functions, in order to
> try to start the socket connection again:
> def keepAlive(self):
> ~ self.alive = 0
> ~ tnow = time.time()
> ~ if tnow - self.lastTime > 90: # last time got from last string
> received from the socket
> ~ self.alive = 1
> def reSocket():
> ~ print "socket has failed", time.strftime('%X', time.localtime())
> ~ time.sleep(60)
> ~ l=GServer() # new instance that contains the socket
> reSocket is triggered when self.alive is 1.
> But it hasn't solved my problem. These functions have effect only after
> I do a ^C, and even then, the socket doesn't start to acquire new input.
> Any clues you can give me about this?
Try setting a default timeout on the socket, and if it times out
recontact the other system on a new socket. See socket.setdefaultimeout()
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com
More information about the Python-list