comparison bot.py @ 52:5aabf124c78d

Fixed XMPP connection closing and the XMPP loop Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Wed, 26 Aug 2009 16:36:18 +0200
parents 2737ed5b9003
children a2258a705a17
comparison
equal deleted inserted replaced
51:2737ed5b9003 52:5aabf124c78d
77 if len(self.xmpp_connections) == 1: 77 if len(self.xmpp_connections) == 1:
78 sleep(0.5) # avoid bot connection being locked all the time 78 sleep(0.5) # avoid bot connection being locked all the time
79 for c in self.xmpp_connections.itervalues(): 79 for c in self.xmpp_connections.itervalues():
80 if hasattr(c, 'lock'): 80 if hasattr(c, 'lock'):
81 c.lock.acquire() 81 c.lock.acquire()
82 if c in self.xmpp_connections.itervalues(): 82 if hasattr(c, 'Process'):
83 if hasattr(c, 'Process'): 83 c.Process(0.01)
84 c.Process(0.01) 84 c.lock.release()
85 c.lock.release()
86 except RuntimeError: 85 except RuntimeError:
87 pass 86 pass
88 except (xml.parsers.expat.ExpatError, xmpp.protocol.XMLNotWellFormed): 87 except (xml.parsers.expat.ExpatError, xmpp.protocol.XMLNotWellFormed):
89 self.error('=> Debug: received invalid stanza', debug=True) 88 self.error('=> Debug: received invalid stanza', debug=True)
90 continue 89 continue
463 c.lock.acquire() 462 c.lock.acquire()
464 c.used_by -= 1 463 c.used_by -= 1
465 if c.used_by < 1: 464 if c.used_by < 1:
466 self.error('===> Debug: closing XMPP connection for "'+nickname+'"', debug=True) 465 self.error('===> Debug: closing XMPP connection for "'+nickname+'"', debug=True)
467 self.xmpp_connections.pop(nickname) 466 self.xmpp_connections.pop(nickname)
467 c.send(xmpp.protocol.Presence(typ='unavailable'))
468 c.lock.release() 468 c.lock.release()
469 del c 469 del c
470 else: 470 else:
471 c.lock.release() 471 c.lock.release()
472 self.error('===> Debug: XMPP connection for "'+nickname+'" is now used by '+str(c.used_by)+' bridges', debug=True) 472 self.error('===> Debug: XMPP connection for "'+nickname+'" is now used by '+str(c.used_by)+' bridges', debug=True)