comparison bot.py @ 49:714e78fb912e

Tried to improve thread-safety during XMPP connection closing. Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Tue, 25 Aug 2009 02:22:27 +0200
parents cb08ea878db9
children dbb7c29a71e2
comparison
equal deleted inserted replaced
48:cb08ea878db9 49:714e78fb912e
75 try: 75 try:
76 try: 76 try:
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, 'Process'): 80 c.lock.acquire()
81 c.lock.acquire() 81 if c in self.xmpp_connections.itervalues():
82 c.Process(0.01) 82 if hasattr(c, 'Process'):
83 c.Process(0.01)
83 c.lock.release() 84 c.lock.release()
84 except RuntimeError: 85 except RuntimeError:
85 pass 86 pass
86 except (xml.parsers.expat.ExpatError, xmpp.protocol.XMLNotWellFormed): 87 except (xml.parsers.expat.ExpatError, xmpp.protocol.XMLNotWellFormed):
87 self.error('=> Debug: received invalid stanza', debug=True) 88 self.error('=> Debug: received invalid stanza', debug=True)
454 c.lock.acquire() 455 c.lock.acquire()
455 c.used_by -= 1 456 c.used_by -= 1
456 if c.used_by < 1: 457 if c.used_by < 1:
457 self.error('===> Debug: closing XMPP connection for "'+nickname+'"', debug=True) 458 self.error('===> Debug: closing XMPP connection for "'+nickname+'"', debug=True)
458 self.xmpp_connections.pop(nickname) 459 self.xmpp_connections.pop(nickname)
460 c.lock.release()
459 del c 461 del c
460 else: 462 else:
461 c.lock.release() 463 c.lock.release()
462 self.error('===> Debug: XMPP connection for "'+nickname+'" is now used by '+str(c.used_by)+' bridges', debug=True) 464 self.error('===> Debug: XMPP connection for "'+nickname+'" is now used by '+str(c.used_by)+' bridges', debug=True)
463 465