Changeset 176


Ignore:
Timestamp:
08/01/05 15:46:06 (19 years ago)
Author:
bastiaans
Message:

daemon/togad.py:

  • (hopefully) REALLY fixed threading exception handling
  • Added IndexError? exception handler for metric .pop() somehow it still happens sometimes
  • Made sure all threads return 0 so they won't hang
  • Added socket.error exception handler for XML parsing
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/togad.py

    r175 r176  
    1010import os.path
    1111import time
     12import thread
    1213import threading
    1314import random
     
    381382                        self.myXMLSource = self.myXMLGatherer.getFileObject()
    382383                        debug_msg( 1, 'torque_xml_thread(): Parsing..' )
    383                         xml.sax.parse( self.myXMLSource, self.myXMLHandler, self.myXMLError )
     384
     385                        try:
     386                                xml.sax.parse( self.myXMLSource, self.myXMLHandler, self.myXMLError )
     387                        except socket.error, msg:
     388                                debug_msg( 0, 'ERROR: Socket error in connect to datasource!: %s' %msg )
     389                               
    384390                        debug_msg( 1, 'torque_xml_thread(): Done parsing.' )
    385391                        debug_msg( 1, 'torque_xml_thread(): Sleeping.. (%ss)' %(str( self.config.getLowestInterval() ) ) )
     
    761767                                        xml_thread = threading.Thread( None, self.processXML, 'xml_thread' )
    762768                                        xml_thread.start()
    763                                 except error, msg:
     769                                except thread.error, msg:
    764770                                        debug_msg( 0, 'ERROR: Unable to start xml_thread!: '+str(msg))
    765771                                        #return 1
     
    773779                                        store_thread = threading.Thread( None, self.storeMetrics, 'store_thread' )
    774780                                        store_thread.start()
    775                                 except error, msg:
     781                                except thread.error, msg:
    776782                                        debug_msg( 0, 'ERROR: Unable to start store_thread!: '+str(msg))
    777783                                        #return 1
     
    790796                        store_metric_thread = threading.Thread( None, self.storeThread, 'store_metric_thread' )
    791797                        store_metric_thread.start()
    792                 except error, msg:
     798                except thread.error, msg:
    793799                        debug_msg( 0, 'ERROR: Unable to start ganglia_store_thread()!: '+str(msg) )
    794800                        return 1
     
    816822                debug_msg( 1, 'ganglia_store_metric_thread(): Storing data..' )
    817823                ret = self.myXMLHandler.storeMetrics()
     824                if ret > 0:
     825                        debug_msg( 0, 'ganglia_store_metric_thread(): UNKNOWN ERROR %s while storing Metrics!' %str(ret) )
    818826                debug_msg( 1, 'ganglia_store_metric_thread(): Done storing.' )
    819827                debug_msg( 1, 'ganglia_store_metric_thread(): finished.' )
    820828               
    821                 return ret
     829                return 0
    822830
    823831        def processXML( self ):
     
    827835                        parsethread = threading.Thread( None, self.parseThread, 'parsethread' )
    828836                        parsethread.start()
    829                 except error, msg:
     837                except thread.error, msg:
    830838                        debug_msg( 0, 'ERROR: Unable to start ganglia_xml_thread()!: ' + str(msg) )
    831839                        return 1
     
    853861                debug_msg( 1, 'ganglia_parse_thread(): Parsing XML..' )
    854862                self.myXMLSource = self.myXMLGatherer.getFileObject()
    855                 ret = xml.sax.parse( self.myXMLSource, self.myXMLHandler, self.myXMLError )
     863
     864                try:
     865                        xml.sax.parse( self.myXMLSource, self.myXMLHandler, self.myXMLError )
     866                except socket.error, msg:
     867                        debug_msg( 0, 'ERROR: Socket error in connect to datasource!: %s' %msg )
     868
    856869                debug_msg( 1, 'ganglia_parse_thread(): Done parsing.' )
    857870                debug_msg( 1, 'ganglia_parse_thread(): finished.' )
    858871
    859                 return ret
     872                return 0
    860873
    861874class GangliaConfigParser:
     
    11151128
    11161129                                        if len( self.myMetrics[ hostname ][ metricname ] ) > 0:
    1117                                                 metrics_to_store.append( self.myMetrics[ hostname ][ metricname ].pop( 0 ) )
     1130
     1131                                                try:
     1132                                                        metrics_to_store.append( self.myMetrics[ hostname ][ metricname ].pop( 0 ) )
     1133                                                except IndexError, msg:
     1134
     1135                                                        pass
    11181136
    11191137                                self.slot.release()
     
    13531371                ganglia_xml_thread.start()
    13541372               
    1355         except error, msg:
     1373        except thread.error, msg:
    13561374                debug_msg( 0, 'FATAL ERROR: Unable to start main threads!: '+ str(msg) )
    13571375                syslog.closelog()
Note: See TracChangeset for help on using the changeset viewer.