Merge remote branch 'tom/hacks'

This commit is contained in:
Brian Beggs 2010-07-01 10:01:52 -04:00
commit f477ccf533
3 changed files with 24 additions and 22 deletions

View File

@ -109,9 +109,9 @@ class basexmpp(object):
if hasattr(self.plugin[plugin], 'xep'): if hasattr(self.plugin[plugin], 'xep'):
xep = "(XEP-%s) " % self.plugin[plugin].xep xep = "(XEP-%s) " % self.plugin[plugin].xep
logging.debug("Loaded Plugin %s%s" % (xep, self.plugin[plugin].description)) logging.debug("Loaded Plugin %s%s" % (xep, self.plugin[plugin].description))
except Exception, e: except:
logging.error("Unable to load plugin: %s" %(plugin) ) logging.exception("Unable to load plugin: %s", plugin )
logging.exception(e)
def register_plugins(self): def register_plugins(self):
"""Initiates all plugins in the plugins/__init__.__all__""" """Initiates all plugins in the plugins/__init__.__all__"""

View File

@ -41,6 +41,7 @@ class Scheduler(object):
def process(self, threaded=True): def process(self, threaded=True):
if threaded: if threaded:
self.thread = threading.Thread(name='shedulerprocess', target=self._process) self.thread = threading.Thread(name='shedulerprocess', target=self._process)
self.thread.daemon = True
self.thread.start() self.thread.start()
else: else:
self._process() self._process()

View File

@ -59,7 +59,7 @@ class XMLStream(object):
self.ssl_support = ssl_support self.ssl_support = ssl_support
self.escape_quotes = escape_quotes self.escape_quotes = escape_quotes
self.state = statemachine.StateMachine(('disconnected','connecting', self.state = statemachine.StateMachine(('disconnected','connecting',
'connected')) 'connected'))
self.should_reconnect = True self.should_reconnect = True
self.setSocket(socket) self.setSocket(socket)
@ -240,7 +240,7 @@ class XMLStream(object):
if self.should_reconnect: if self.should_reconnect:
self.disconnect(reconnect=True) self.disconnect(reconnect=True)
logging.debug('Quitting Process thread') logging.debug('Quitting Process thread')
def __readXML(self): def __readXML(self):
"Parses the incoming stream, adding to xmlin queue as it goes" "Parses the incoming stream, adding to xmlin queue as it goes"
@ -306,23 +306,24 @@ class XMLStream(object):
return True return True
def disconnect(self, reconnect=False): def disconnect(self, reconnect=False):
if not self.state.transition('connected','disconnected'): with self.state.transition_ctx('connected','disconnected') as locked:
logging.warning("Already disconnected.") if not locked:
return logging.warning("Already disconnected.")
logging.debug("Disconnecting...") return
self.sendPriorityRaw(self.stream_footer) logging.debug("Disconnecting...")
time.sleep(5) self.sendRaw(self.stream_footer)
#send end of stream time.sleep(5)
#wait for end of stream back #send end of stream
try: #wait for end of stream back
# self.socket.shutdown(socket.SHUT_RDWR) try:
self.socket.close() # self.socket.shutdown(socket.SHUT_RDWR)
except socket.error as (errno,strerror): self.socket.close()
logging.exception("Error while disconnecting. Socket Error #%s: %s" % (errno, strerror)) except socket.error as (errno,strerror):
try: logging.exception("Error while disconnecting. Socket Error #%s: %s" % (errno, strerror))
self.filesocket.close() try:
except socket.error as (errno,strerror): self.filesocket.close()
logging.exception("Error closing filesocket.") except socket.error as (errno,strerror):
logging.exception("Error closing filesocket.")
if reconnect: self.connect() if reconnect: self.connect()